Hello,
consider the following statements,
int *pBuf = new int[10]; //this will allocate 10*sizeof(int) memory
delete []pBuf // this will delete all the memory allocated to pBuf
Question: How come the application knows that it has to delete memory of
pBuf for 10 * sizeof(int) from the statement "delete []pBuf "?
Pls. reply back
John 6 1718
On 2007-12-24 00:57:39 -0500, "AS" <as**********@rediffmail.comsaid:
Hello,
consider the following statements,
int *pBuf = new int[10]; //this will allocate 10*sizeof(int) memory
delete []pBuf // this will delete all the memory allocated to pBuf
Question: How come the application knows that it has to delete memory of
pBuf for 10 * sizeof(int) from the statement "delete []pBuf "?
Pls. reply back
John
Same way how free() knows how much memory to reclaim from malloc(): It
keeps internal data structure on what pieces of memory were issued.
--
-kira
Thanx for the reply. I guessed the same. Can you explain in detail or any
sample code to demonstrate this ?
"Kira Yamato" <ki*****@earthlink.netwrote in message
news:2007122400425016807-kirakun@earthlinknet...
On 2007-12-24 00:57:39 -0500, "AS" <as**********@rediffmail.comsaid:
>Hello, consider the following statements, int *pBuf = new int[10]; //this will allocate 10*sizeof(int) memory
delete []pBuf // this will delete all the memory allocated to pBuf
Question: How come the application knows that it has to delete memory of pBuf for 10 * sizeof(int) from the statement "delete []pBuf "?
Pls. reply back
John
Same way how free() knows how much memory to reclaim from malloc(): It
keeps internal data structure on what pieces of memory were issued.
--
-kira
"Kira Yamato" <ki*****@earthlink.netwrote in message
news:2007122400425016807-kirakun@earthlinknet...
>On 2007-12-24 00:57:39 -0500, "AS" <as**********@rediffmail.com> said:
>>Hello, consider the following statements, int *pBuf = new int[10]; //this will allocate 10*sizeof(int) memory delete []pBuf // this will delete all the memory allocated to pBuf Question: How come the application knows that it has to delete memory of pBuf for 10 * sizeof(int) from the statement "delete []pBuf "?
>Same way how free() knows how much memory to reclaim from malloc(): It keeps internal data structure on what pieces of memory were issued.
Thanx for the reply. I guessed the same. Can you explain in detail or
any sample code to demonstrate this ?
It's the compiler/OS that keeps track. It may be done differently in
different compilers and OSes. I think you gave the perfect example, what
more would you need?
--
Jim Langston ta*******@rocketmail.com
I would like to know how this is happening internally, suppose that if we
have to write our own Memory Manager which handle these ?
"Jim Langston" <ta*******@rocketmail.comwrote in message
news:Ne*************@newsfe05.lga...
>"Kira Yamato" <ki*****@earthlink.netwrote in message news:2007122400425016807-kirakun@earthlinknet...
>>On 2007-12-24 00:57:39 -0500, "AS" <as**********@rediffmail.com> said: Hello, consider the following statements, int *pBuf = new int[10]; //this will allocate 10*sizeof(int) memory delete []pBuf // this will delete all the memory allocated to pBuf Question: How come the application knows that it has to delete memory of pBuf for 10 * sizeof(int) from the statement "delete []pBuf "?
>>Same way how free() knows how much memory to reclaim from malloc(): It keeps internal data structure on what pieces of memory were issued.
>Thanx for the reply. I guessed the same. Can you explain in detail or any sample code to demonstrate this ?
It's the compiler/OS that keeps track. It may be done differently in
different compilers and OSes. I think you gave the perfect example, what
more would you need?
--
Jim Langston ta*******@rocketmail.com
AS wrote:
Please don't top-post.
"Jim Langston" <ta*******@rocketmail.comwrote in message
news:Ne*************@newsfe05.lga...
>>"Kira Yamato" <ki*****@earthlink.netwrote in message news:2007122400425016807-kirakun@earthlinknet... On 2007-12-24 00:57:39 -0500, "AS" <as**********@rediffmail.com> said: Hello, consider the following statements, int *pBuf = new int[10]; //this will allocate 10*sizeof(int) memory delete []pBuf // this will delete all the memory allocated to pBuf Question: How come the application knows that it has to delete memory of pBuf for 10 * sizeof(int) from the statement "delete []pBuf "? Same way how free() knows how much memory to reclaim from malloc(): It keeps internal data structure on what pieces of memory were issued. Thanx for the reply. I guessed the same. Can you explain in detail or any sample code to demonstrate this ?
It's the compiler/OS that keeps track. It may be done differently in different compilers and OSes. I think you gave the perfect example, what more would you need?
Or quote signatures.
>>
I would like to know how this is happening internally, suppose that if we
have to write our own Memory Manager which handle these ?
The answer is part of your operating system or runtime libraries. If
you can , consult the source for those. Writing your own memory manager
is an excellent way to understand the problems involved with dynamic
memory management.
--
Ian Collins.
On Dec 24, 12:43*pm, "AS" <asudhakar...@rediffmail.comwrote:
I would like to know how this is happening internally, suppose that if we
have to write our own Memory Manager which handle these ?
Consider going through the C++ FAQ lite - http://www.parashift.com/c++-faq-lit...html#faq-16.14 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Dave |
last post by:
Hello all,
In the code below, I see the following output:
base::operator new(size_t, int)
base::base()
base::~base()
base::operator delete(void *)
In the case of an exception being thrown...
|
by: Nimmi Srivastav |
last post by:
There's a rather nondescript book called "Using Borland C++" by Lee
and Mark Atkinson (Que Corporation) which presents an excellent
discussion of overloaded new and delete operators. In fact there...
|
by: Nimmi Srivastav |
last post by:
There's a rather nondescript book called "Using Borland C++" by Lee
and Mark Atkinson (Que Corporation) which presents an excellent
discussion of overloaded new and delete operators.
I am...
|
by: Douglas Peterson |
last post by:
class Allocator
{
public:
virtual void * Alloc(size_t) = 0;
virtual void * Free(void*) = 0;
};
class Object
{
public:
|
by: Dave |
last post by:
Hello all,
I'd like to find a source on the web that discusses, in a comprehensive
manner and in one place, everything about new / delete. It should include
overloading operator new, the new...
| |
by: silver360 |
last post by:
Hello,
I'm trying to create a basic Heap manager and i have some question
about new/delete overloading.
The following code give me this output :
>> $./heap
>> registered : 0x804d098
>>...
|
by: rohits123 |
last post by:
I have an overload delete operator as below
//////////////////////////////////
void operator delete(void* mem,int head_type) {
mmHead local_Head = CPRMemory::GetMemoryHead(head_type);...
|
by: jeffjohnson_alpha |
last post by:
We all know that a new-expression,
foo* a = new foo() ;
allocates memory for a single foo then calls foo::foo(). And we know
that
void* p = ::operator new(sizeof(foo)) ;
allocates a...
|
by: LuB |
last post by:
I am constantly creating and destroying a singular object used within
a class I wrote.
To save a bit of time, I am considering using 'placement new'. I guess
we could also debate this decision -...
|
by: =?Utf-8?B?R2Vvcmdl?= |
last post by:
Hello everyone,
I remembered delete is implemented through operator overloading, but I am
not quite clear.
Could anyone recommend some links about how delete is implemented so that
I can...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |