473,387 Members | 1,771 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Working of the delete [ ] operator

Hi,

I'd like to know how heap aggregates created with a "new" operator at
non-contiguous memory locations get deallocated using the "delete []"
operator in VC++.

A garbage collectors in Java deallocate on the basis of a record
maintained during the "new" allocation.

Do we use something like a garbage collector to maintain arecord of
the heap memory start indexes.

Please enlighten me.

Thanks,

Megha.
Jul 19 '05 #1
3 2476
On 15 Oct 2003 03:08:52 -0700, vm****@vsnl.com (Megha Vishwanath)
wrote:
Hi,

I'd like to know how heap aggregates created with a "new" operator at
You mean the new[] operator?
non-contiguous memory locations get deallocated using the "delete []"
operator in VC++.
There is a header before the bit of memory that new[] returns that
gives the size of the allocated block. A call to delete[] then uses
this size to
a) work out how many objects to destruct
b) actually deallocate the memory
A garbage collectors in Java deallocate on the basis of a record
maintained during the "new" allocation.
Same in C++ - the memory allocator keeps track of the size of
allocations. Different allocators do this differently.

Do we use something like a garbage collector to maintain arecord of
the heap memory start indexes.


No. You should read up on memory allocators:

http://www.memorymanagement.org

Tom
Jul 19 '05 #2
tom_usenet wrote:
On 15 Oct 2003 03:08:52 -0700, vm****@vsnl.com (Megha Vishwanath)
wrote:
Hi,

I'd like to know how heap aggregates created with a "new" operator at


You mean the new[] operator?
non-contiguous memory locations get deallocated using the "delete []"
operator in VC++.


There is a header before the bit of memory that new[] returns that
gives the size of the allocated block. A call to delete[] then uses
this size to
a) work out how many objects to destruct
b) actually deallocate the memory


Just to mention: That's one way to do it. The C++ standard doesn't
specify how this is to be done, and there are other ways.

Jul 19 '05 #3
Thanx Tom!
Jul 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
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...
5
by: Yang Lee | last post by:
Hi, Could you please try to run the following program it doesnt work for operator overloading function. It doesn't print peoper empName for emp2 object. It prints junk. Just what could be the...
1
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...
20
by: Ioannis Vranos | last post by:
When we use the standard placement new operator provided in <new>, and not a definition of owr own, isn't a call to placement delete enough? Consider the code: #include <new>
1
by: =steFF= | last post by:
Hi, I am trying to print the values I have in a vector and my compiler says: error C2227: left of '->printLn' must point to class/struct/union on this instruction: m_data->printLn(); (in my file...
3
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 >>...
5
by: junw2000 | last post by:
I use the code below to study delete and destructor. #include <iostream> using namespace std; struct A { virtual ~A() { cout << "~A()" << endl; }; //LINE1 void operator delete(void* p) {...
6
by: Lighter | last post by:
Big Problem! How to overload operator delete? According to C++ standard, "A deallocation function can have more than one parameter."(see 3.7.3.2); however, I don't know how to use an overloaded...
12
by: yufufi | last post by:
Hello, How does delete know how much memory to deallocate from the given pointer? AFAIK this informations is put there by new. new puts the size of the allocated memory before the just before...
10
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...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
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 using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.