🔒 Locked
C++ delete question
Advertisement
Original Post
it allocated much more extra bytes. Sometime ago I figuered out that it was 18 bytes if I''m not mistaking before the pointer. But you shouldn''t use that, because you never know if it will work on other systems/windows versions, and you can be quite sure it won''t be cross platform.
My Site
My Site
Looks this is what is happening!!
When you declare int *ARRAY = new int[10];, the compiler goes to the heap (a section in where you can allocate memory that lies on RAM) and set memory aside for your data. In this case you are telling to the compiler to set aside 10 int''s or 10 * 4 = 40 bytes. But how do the compiler knows where the memory is?..Well that is why we declare variables...I this case ARRAY is a constant Address,,,or a Pointer to the first byte of the 40 bytes we set aside on memory. Therefore, when you call
delete[] ARRAY;
Your compiler goes to the Address that ARRAY is holding and free the same amount of bytes that you set aside when you reserved that portion of data.
In this case 40 bytes.
ASW
When you declare int *ARRAY = new int[10];, the compiler goes to the heap (a section in where you can allocate memory that lies on RAM) and set memory aside for your data. In this case you are telling to the compiler to set aside 10 int''s or 10 * 4 = 40 bytes. But how do the compiler knows where the memory is?..Well that is why we declare variables...I this case ARRAY is a constant Address,,,or a Pointer to the first byte of the 40 bytes we set aside on memory. Therefore, when you call
delete[] ARRAY;
Your compiler goes to the Address that ARRAY is holding and free the same amount of bytes that you set aside when you reserved that portion of data.
In this case 40 bytes.
ASW
quote:...but that doesn''t make any sense. You want: "It''s magic.", with the apostrophe.
Original post by C-Junkie
i decree that from now on, this question will be answered with two words, "its magic."
quote:
Original post by Anonymous Poster
Now explain the magic behind stack unwinding![]()
First you wind the stack then you unwind it... using Voodoo.
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement