THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 25/09/2005 at 15:34, xxxxxxxx wrote:
Cinema 4D Version: 8.503
Platform: Windows ; Mac ; Mac OSX ;
Language(s) : C++ ;
Just curious here. I take it that the gNew and bNew operators do not have placement support. Any way around that?
On 02/10/2005 at 08:19, xxxxxxxx wrote:
have a look at c4d_memory.h gNew and bNew are just macros that use the new operator with the __LINE__ and __FILE__ argument.
The default placement new operator is defined in new.h of the c std lib.
It doesn't actually do anything.. just returns a pointer it was passed. The compiler seems to handle the constructor call after the placement new operator returns.
There is no placement new for arrays...none that i could find. So you have to loop over all elements construct each one.
Would you explain what you want to do ? I'm quite curious. From what you have written i would say you wanted to write your own memory manager.. probably an automated garbage collection.. I'm not sure if it would be worth the effort ( at least if you don't want a automated garbage collector ) I mean there is surely a need to have array and liked list classes and such.. There is the STL but i can see why you don't want to use it. After all i also have written my own array, linked list, and hash table.. But i think it is safe to assume that Cinema's Memory Manager is indeed very fast and robust. It has to be because Cinema also has to deal with lots of allocatons of any size, persistency.. and whatever. I made some tests and on my system GeAlloc can allocate and free about 100000 small 8 byte blocks in a few msecs.
On 02/10/2005 at 10:29, xxxxxxxx wrote:
Not garbage collection, just a way to place many class instances (my own, not C4Ds) into a particular MemoryPool in order to avoid memory fragmentation. Generic memory allocations can be done into the MemoryPool, but classes require placement new for such a task.
I am prepassing to count as much as possible to allocate larger blocks of memory, but there are still fragmentation issues since I am allocating many temporary blocks for processing/compressing/decompressing interspersed with creation of permanent C4D objects. The memory requirements for any file are not completely quantifiable - could be virtually nothing to gigabytes. These files reference other files in turn which only logarithmically complicates the process.
One person in an article mentioned one way is to allocate all permanent memory (C4D objects) first and transient memory (parsing classes and whatnot) afterwards. This is an impossibility when dealing with this flexible, hierarchical, extrareferential file format. There is no way to know of all of the permanent needs until after parsing the entire file (and its referenced files) and doing some complex determinations (the same complex determinations that constitute the plugin itself). So, I'd practically need to run the entire process twice which would incur some form of memory usage to store information to reduce memory usage (etc., etc.) as well as an unacceptable slow down for users.
It's not really a matter of allocation speed as usage. There are no leaks, it is just that system reclamation is very slow.
On 03/10/2005 at 10:18, xxxxxxxx wrote:
Cinemas MemoryPool class seems to be just what you need.
I use the placment new op for my array classes on memory allocated with GeAlloc. It seems to work fine
There could be problem with the MemoryPool though. Freeing Memory with pool->FreeMem is very slow if you free lots of allocations in random order... but if you just read a file and free all memory afterwards then it's ok because you can just destroy the entire pool.