MemoryPool and classes/class arrays?



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 02/11/2004 at 23:33, xxxxxxxx wrote:

    User Information:
    Cinema 4D Version:   8.503 
    Platform:   Windows  ;   
    Language(s) :     C++  ;

    ---------
    Is it possible to use the MemoryPool class memory to allocate/store classes and class arrays (instead of using gNew/bNew)?

    If not, is there any way to reduce heap fragmentation beyond the known approaches:

    1. less dynamic allocation - can't be helped, I'm parsing massive, very flexible files into numerous classes and massive objects with massive data. Alot of this memory (mainly classes) is freed immediately (and completely) after use.

    2. larger allocation blocks - has helped minimally so far. Because I use a class system to encapsulate the file section types, bNew EveryClassType[n] just won't do, now will it? If you think otherwise, please elucidate.

    3. compression, optimizations, etc. - have helped greatly, but not sufficiently enough.

    I've never had to deal with memory usage on this scale, so any help, links, pointers will be appreciated!

    Thanks,
    Robert



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 03/11/2004 at 03:40, xxxxxxxx wrote:

    If it's a POD (plain old datatype, see http://www.parashift.com/c++-faq-lite/intrinsic-types.html#faq-26.7) then it's of course no problem. Just alloc the right amount of memory and use it by casting. (Some classes, like Vector, aren't true PODs, but close enough that I'd trust the compiler to be able to handle them.)
    If it's not a POD but allocatable by gNew then you could use placement new to still force the constructor to be called. There's a neat trick to do this automatically with a memory pool object, as can be seen in http://www.parashift.com/c++-faq-lite/dtors.html#faq-11.10.
    Finally, if it's a C4D object that has to be allocated with Alloc() and deallocated with Free() then I think you're out of luck. These can't be allocated in your own memory pool.



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 03/11/2004 at 08:50, xxxxxxxx wrote:

    Luckily, all of the C4D objects (including plugin tags) are added to the document, so I leave them to the mercy of C4D's internal memory handling. Everything else is arrays of either PODs or my own classes.

    Now, I think it's time to get drunk waiting for four more years of the same... :(

    Thanks Mikael,
    Robert


Log in to reply