Hi,
I have a basic doubt.
Test *t = new Test[10];
....
delete t;
Will the "delete t" deallocates the memory for all the 10 Test objects or it
just deallocates for the first Test object?
In some article I have read, it deallocates the memory for all the 10 Test
objects and the destructor will be called for the first Test object. Is it
correct?
In case of Primitive types, is the behavior same or different?
Regards,
VSP 3 1335
On 17 Srp, 09:06, "VSP" <a...@abc.comwrote:
Hi,
I have a basic doubt.
Test *t = new Test[10];
...
delete t;
Will the "delete t" deallocates the memory for all the 10 Test objects or it
just deallocates for the first Test object?
In some article I have read, it deallocates the memory for all the 10 Test
objects and the destructor will be called for the first Test object. Is it
correct?
In case of Primitive types, is the behavior same or different?
Regards,
VSP
Hi.
Use of delete for data allocated with new[] is wrong. You cannot
assume any behaviour, since it is error. It may work for particular
compiler, but it would be non-portable program.
Ondrej
VSP wrote:
Hi,
I have a basic doubt.
Test *t = new Test[10];
...
delete t;
Will the "delete t" deallocates the memory for all the 10 Test objects or
it just deallocates for the first Test object?
Actually, it's undefined behaviour, so anything could happen.
In some article I have read, it deallocates the memory for all the 10 Test
objects and the destructor will be called for the first Test object. Is it
correct?
For some compiler, it might do. On other compilers, it might crash your
system.
In case of Primitive types, is the behavior same or different?
The behaviour is undefined in both cases. Use 'delete [] t' as your
teacher/book/... hopefully told you.
--
rbh
On Fri, 17 Aug 2007 12:36:33 +0530, VSP wrote:
Hi,
I have a basic doubt.
Test *t = new Test[10];
...
delete t;
delete[] t;
>
Will the "delete t" deallocates the memory for all the 10 Test objects or it
just deallocates for the first Test object?
In some article I have read, it deallocates the memory for all the 10 Test
objects and the destructor will be called for the first Test object. Is it
correct?
In case of Primitive types, is the behavior same or different?
You should always match 'new' to 'delete', and 'new[]' to 'delete[]'.
--
Obnoxious User This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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: Roy Smith |
last post by:
I understand that "delete xp" deletes a scalar object and "delete xp"
deletes an array of objects, but what I don't understand is why you need
to tell the compiler which you're doing.
When you...
|
by: DamonChong |
last post by:
Hi,
I am new to c++. I recently spend an enormous among of time
troubleshooting a seeminly innocuous piece of code. Although I narrow
down this piece of code as the culprit but I don't...
|
by: tony collier |
last post by:
This is an array question but it is based in my web page so i shall give
scenario:
when the client navigates to the page, the page takes some figures and does
loads of calulations in page_load...
|
by: Richard Arthur |
last post by:
This is a weird problem.
1) I use MediaDet to save a bitmap in a temporary file.
2) I create a bitmap using that temporary file's name.
3) I use the bitmap.
4) I want to destroy the file when...
|
by: AB |
last post by:
Hi all,
A thought crossed my mind....
if I allocate memory for an array at runtime using....
int* arr = new int ;
what happens when I then de-allocate memory using
|
by: mkaushik |
last post by:
Hi everyone,
Im just starting out with C++, and am curious to know how "delete
<pointer>", knows about the number of memory locations to free.
I read somewhere that delete frees up space...
|
by: Money |
last post by:
If I allocate memory like this
int *ptr = new int;
Can I apply delete ptr; instead of delete ptr; since I am only
allocating memory for 1 integer.
|
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...
|
by: subramanian100in |
last post by:
Suppose
class Base
{
public:
virtual ~Test() { ... }
// ...
};
class Derived : public Base
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
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...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
| |