|
From: James W. W. <ja...@wr...> - 2005-01-24 18:41:37
|
At 1:23 PM +0000 1/24/05, Roger Holmes wrote: >For my remaining 'slack' time I would like your opinions on the >possible use of C++ memory >allocation and construction facilities. On Macintosh I think that >using statements like: > > E3ClassInfo* theInfo = new E3ClassInfo ; > >E3ClassInfo* theClass = (E3ClassInfo*) Q3Memory_AllocateClear ( >sizeof ( E3ClassInfo ) ) ; > >are (except for the zeroing of the block of memory) equivalent as >they both end up calling >malloc to actually reserve the memory. Am I correct, and what is the >situation on the other >platforms? When compiled with Q3_MEMORY_DEBUG, E3Memory_AllocateClear uses a block trailer to test for buffer overruns. Exactly what operator new does on the Mac with CodeWarrior depends on whether we're talking CFM or Mach-O, and what options were used to compile the runtime library. The default on Mach-O is that operator new calls malloc. Also bear in mind that E3ClassInfo* theInfo = new E3ClassInfo ; would throw an exception if the allocation fails, unless you write it as E3ClassInfo* theInfo = new(std::nothrow) E3ClassInfo ; -- James W. Walker, ScriptPerfection Enterprises, Inc. <http://www.write-brain.com/> |