Subj : Re: the use of new; allocating memory To : borland.public.cpp.borlandcpp From : Andrue Cope Date : Mon Dec 08 2003 11:44 am Howie, > When you use new (or malloc) to allocate memory, what is really happening here? Does Windows see it? I know you can allocate memory through Windows, asking for a chunck of memory but if you use "new" (C++ keyword), then are you going around Windows for your memory needs? > You are asking the Heap Manager for a pointer to a currently unused area of memory of the size specified. The HM is at complete liberty to generate a pointer how it sees fit and most HMs do not pass your requests straight through to the OS. This is because most OSes can't track very many allocations per process (I think Win32 can only track 65536) so the HM has to be a bit clever. The significant point here is that the HM is trying to reduce the number of times that it has to ask the OS for memory. It does this by suballocating the larger chunks. The result is that if you could query the OS about the number of memory blocks it has allocated to your process it will be significantly less than the number of allocations your process currently has active. It also means that the first time you ask for a six byte memory block the HM will probably ask the OS for considerably more - several kB. If you then ask the HM for an additional six bytes the pointer returned will be close to the first one. Exactly how close depends on how the HM is implemented but it /might/ simply be six bytes after the first pointer. -- Andrue Cope [Bicester, UK] .