🔒 Locked
new/malloc
Advertisement
Original Post
I''m a C programmer still trying to get used to C++. Is there any difference between the memory the new allocates and the memory that malloc allocates, or are they pretty much the same. Also, if I''m programming Win32, should I use windows memory functions, or doesn''t it really matter?
Thanx
- IO Fission
Tearing 'em apart for no particular reason...
Something similar to realloc must be done manually: first create the new storage, copy all the elements, and then delete the old storage and finally use the address of the old storage. Realloc essentially does the same.
But, since you already use the STL stuff, realloc isn''t really needed, except (maybe?) for low-level things.
Erik
But, since you already use the STL stuff, realloc isn''t really needed, except (maybe?) for low-level things.
Erik
Using new and delete would just be better style in C++, unless of course you are old school like me.
-----------------------------
A wise man once said "A person with half a clue is more dangerous than a person with or without one."
-----------------------------
A wise man once said "A person with half a clue is more dangerous than a person with or without one."
The heap functions (HeapCreate, HeapAlloc, HeapFree, HeapDestroy) are the "preferred" ways of allocating memory under Win32. The C/C++ allocaters use these internally. You may gain a minor performance increase if you use these functions instead of the new/malloc.
Remember, you can globally override operator new to use whatever allocation scheme you choose.
Remember, you can globally override operator new to use whatever allocation scheme you choose.
Ok, so from what I''ve gathered they all get the same memory anyway, just using different funcitons to end up calling the same thing (including the constructors/destructors part for new).
Thanx all for helping to clarify that!
- IO Fission
Tearing 'em apart for no particular reason...
Thanx all for helping to clarify that!
- IO Fission
Tearing 'em apart for no particular reason...
When is it correct to use delete[]?
If I create a float vector,
is it correct to destroy this memory with delete[]?
or should it be just delete.
Thanks,
Gandalf the White
You'll find a golden ring...
Edited by - Gandalf on July 7, 2000 8:14:06 AM
If I create a float vector,
float *data;
data = new float[32*32*3];
is it correct to destroy this memory with delete[]?
or should it be just delete.
Thanks,
Gandalf the White
You'll find a golden ring...
Edited by - Gandalf on July 7, 2000 8:14:06 AM
How do you allocate an array of structures using new? The way with malloc is malloc(num_elements * sizeof(structure)), but I am interested to know how it is done with new.
I prefer malloc, as it is closer to what the computer actually does.
------------------------------
#pragma twice
I prefer malloc, as it is closer to what the computer actually does.
------------------------------
#pragma twice
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement