overhead of NEW and DELETE
-
Hi All, I would like to ask regarding the possible overhead/performance issue for an application (DLL) to create an object (call NEW) and destroy the object (DELETE) every 1 second? Thanks so much. not so newbie :)
-
Hi All, I would like to ask regarding the possible overhead/performance issue for an application (DLL) to create an object (call NEW) and destroy the object (DELETE) every 1 second? Thanks so much. not so newbie :)
PSEUDOCODE
int *varArray[1000000];
StartNewTime = getSystemTimer();
for (i=0; i<1000000; i++)
varArray[i] = new int;StartDelTime = getSystemTimer();
for (i=0; i<1000000; i++)
delete varArray[i];endTime = getSystemTimer();
elapsedNewTime = StartDelTime - StartNewTime;
elapsedDelTime = endTime - StartDelTime;timePerNew = (float) elapsedNewTime / 1000000.0;
timePerDel = (float) elapsedDelTime / 1000000.0;Of course, if they were C++ objects that were calling constuctors & destructors, then the answer would be different, and you would need to have an array of 1000000 (or whatever other arbitrary number suits you) pointers to objects of the type to be investigated. Just remember - if 1 event is too quick to time effectively, then just time a whole heap of them at once.
-
Hi All, I would like to ask regarding the possible overhead/performance issue for an application (DLL) to create an object (call NEW) and destroy the object (DELETE) every 1 second? Thanks so much. not so newbie :)
Anytime you employ the use of Windows' memory manager, there will be some overhead involved. It may be negligible, but there will be some. Is it really part of your design to allocate and release memory every second?
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
-
Hi All, I would like to ask regarding the possible overhead/performance issue for an application (DLL) to create an object (call NEW) and destroy the object (DELETE) every 1 second? Thanks so much. not so newbie :)
ginjikun wrote:
I would like to ask regarding the possible overhead/performance issue for an application (DLL) to create an object (call NEW) and destroy the object (DELETE) every 1 second?
could it don't by allocating static memory, instead of using dynamic memory. yes there could be dynamic issue, as memory allocation itself is tedious task. how big is data??, could you code like this :- if( MEMORY_REQUIRED > STATIC_MEMORY_ALLOCATED) allocate DYNAMIC_MEMORY else use STATIC_MEMORY now you have choose STATIC_MEMORY_ALLOCATED limits according to you.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
Never mind - my own stupidity is the source of every "problem" - Mixturecheers, Alok Gupta VC Forum Q&A :- I/IV Support CRY- Child Relief and You/xml>
-
Hi All, I would like to ask regarding the possible overhead/performance issue for an application (DLL) to create an object (call NEW) and destroy the object (DELETE) every 1 second? Thanks so much. not so newbie :)
Every 1 second is not very often relative to how many operations can be done in one second by a modern PC. I can allocate/free hundreds of video frame buffers a second using barely any CPU. If your allocations are too slow (for reasons others have mentioned) then you can implement some kind of pre-allocated memory scheme. Mark
Mark Salsbery Microsoft MVP - Visual C++ :java: