Announcement

Collapse
No announcement yet.

Some questions about the new objects

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • José Roca
    replied
    1. OBJPTR, What would you use this for. You can't assign the pointer to an object so what is the intended use?
    You CAN assign a pointer to an object variable. Not natively, but using POKE or pointers.

    Sometimes you need to pass a pointer to a class to a function that has the parameter declared as DWORD or LONG, e.g.

    Code:
             ' Set the IRichEditOleCallback object.
             ' The control calls the AddRef function for the object before returning.
             LOCAL pRichEditOleCallback AS IRichEditOleCallbackImpl
             pRichEditOleCallback = CLASS "CRichEditOleCallback"
             SendMessage hWndChild, %EM_SETOLECALLBACK, 0, OBJPTR(pRichEditOleCallback)

    Leave a comment:


  • Fred Harris
    replied
    Objptr()

    Mark's original question got me to to thinking about Objptr. I was vaguely aware of its existance, but I decided to try and figure it out. The result of my explorations are in source code at...

    Leave a comment:


  • Theo Gottwald
    replied
    I've tried it on one-dimensional arrays - and works fine.
    One dimensional Arrays always worked fine.

    Ok, the helpfile says:

    When PRESERVE is specified, you can resize only the upper boundary of the last (outer) dimension of the array. Arrays of only one dimension can always be resized.


    I may look at this at next chance for a multidimensional Array like 3 or 4 Dimensions, if it really keeps data. Together with the new objects this could become interesting for small Data-Applications.

    Leave a comment:


  • Michael Mattias
    replied
    > let's imagine a hash based in-memory dictionary ...

    If I had to store that much info, I doubt I'd try to force the keys into virtual memory using classes or anything else.

    Of course, that would mean I would have to restrict the application to systems which actually have a disk drive. I can live with that.

    But if I had to fit an index into virtual memory, I'm pretty sure I could index 2.5 Mb records in about, oh, call it 2.5 Million * SIZEOF(Key) bytes.

    And if I had to use a 512-byte key, I think I would.... have my head examined.

    Leave a comment:


  • Richard Angell
    replied
    The thing to remember is that object creation has a base cost which I estimate at roughly 512 bytes per object (not counting space needed for INSTANCE variables, etc.) so that declaring large amounts of objects can quickly exhaust the amount of memory available at which point you'll run into a run-time exception. But it's a handy technique when you need it.
    Have you measured this, or just guessed?

    I wrote a simple do-next-to-nothing class with one method, one property and one instance variable ... 132 bytes per object. The size of the object is really going to proportional what is in the class and interface.

    Leave a comment:


  • Florent Heyworth
    replied
    Hi Michael

    actually you may run out before hitting the 4 million limit depending on the number of instance variables, within your object as well as the memory allocator you use. And the cautionary note is not made without reason:

    consider a data repository, let's imagine a hash based in-memory dictionary used to store lots of keys and their corresponding values. Each structure within the dictionary may have been expressed as a type prior to PB9. The temptation to use a self-contained class with access methods to the UDT members could lead to redefining each dynamically declared type as a class with unexpected results. While 2.5 million class instances may sound like a lot, 2.5 million records is not all that much...

    Cheers, Florent

    Leave a comment:


  • Michael Mattias
    replied
    512 bytes per object (not counting space needed for INSTANCE variables, etc.) so that declaring large amounts of objects can quickly exhaust the amount of memory available
    Yeah, at that rate you are limited to only a little over 4 million. What a bummer.

    Too bad there's no commands to free up those you aren't using right now.

    Or maybe you could get around this problem by actually thinking about how much memory the application might use BEFORE you start coding.... nah, wait a minute, forget this one.... that's simply asking too much.

    Leave a comment:


  • Florent Heyworth
    replied
    Originally posted by Theo Gottwald View Post
    Nr.3 is a interesting question. Also if

    REDIM PRESERVE

    can be used, on (multidimesional?) Arrays of objects.

    I couldn't do much until now, but these are things I 'd be interested to look at.
    I've tried it on one-dimensional arrays - and works fine.

    you can do

    Code:
    'not compilable - just showing
    
    LOCAL a() as MY_INTERFACE
    
    REDIM a(2000)
    
    FOR i = LBOUND(a) TO UBOUND(a)
         a = CLASS "MyClass"
    NEXT 
    
    ' you can also do
    LOCAL b() AS MY_INTERFACE
    
    REDIM a(2000) AT ADRESS_OF_MEMORY_YOU_CREATED
    The thing to remember is that object creation has a base cost which I estimate at roughly 512 bytes per object (not counting space needed for INSTANCE variables, etc.) so that declaring large amounts of objects can quickly exhaust the amount of memory available at which point you'll run into a run-time exception. But it's a handy technique when you need it.

    Leave a comment:


  • Theo Gottwald
    replied
    Nr.3 is a interesting question. Also if

    REDIM PRESERVE

    can be used, on (multidimesional?) Arrays of objects.

    I couldn't do much until now, but these are things I 'd be interested to look at.

    Leave a comment:


  • Mark Smit
    started a topic Some questions about the new objects

    Some questions about the new objects

    Hey guys,

    I've got a couple questions that hopefully can be answered...

    1. OBJPTR, What would you use this for. You can't assign the pointer to an object so what is the intended use?

    2. Is there any native way to copy only the instance variables between two different objects of the same interface type? Or should this be done with a user defined "Copy" method.

    Code:
    dim Object1 as IObject
    dim Object2 as IObject
    
    Object1 = class "CObject"
    Object2 = class "CObject"
    
    Object1.InstanceVars = Object2.InstanceVars
    3. Is it possible to create a generic interface variable which can be assigned an interface type at run time.

    Code:
    dim Record as IGeneric
    
    select case lRecordType
        case %RECORD_ADDRESS
            redim Record as IAddress
            Record = class "CAddress"
        case %RECORD_PERSON
            redim Record as IPerson
            Record = class "CPerson"
        case %RECORD_COMMENTS
            redim Record as IComments
            Record = class "CComments"
    end select
    4. When creating an array of object interfaces, is the following a "safe" way to use the ARRAY INSERT/DELETE statements?

    Code:
    dim Record(10) as IRecord
    dim lRow as long
    
    for lRow = 0 to ubound(Record)
        Record(lRow) = class "CRecord"
    next
    
    'Allocate DWORD array over object array
    dim RecordIndex(ubound(Record)) as dword at varptr(Record(0))
    
    'Destroy object reference at row 5
    Record(5) = nothing
    
    'Delete array element 5 using array delete
    array delete RecordIndex(5)

    Thanks!
Working...
X