| View previous topic :: View next topic |
| Author |
Message |
wijhierbeneden Guest
|
Posted: Thu Oct 28, 2004 7:42 pm Post subject: new algorithm |
|
|
Hello
Where can I find some info about the inner working of new/delete??
Is this compiler specific or defined by the standard?? There is a lot
of info about the different malloc implementations but I can't find
anything about new.
thx
|
|
| Back to top |
|
 |
Victor Bazarov Guest
|
Posted: Thu Oct 28, 2004 7:44 pm Post subject: Re: new algorithm |
|
|
wijhierbeneden wrote:
| Quote: | Where can I find some info about the inner working of new/delete??
Is this compiler specific or defined by the standard?? There is a lot
of info about the different malloc implementations but I can't find
anything about new.
|
What do you want to know? What C++ book do you have?
|
|
| Back to top |
|
 |
Ron Natalie Guest
|
Posted: Thu Oct 28, 2004 8:45 pm Post subject: Re: new algorithm |
|
|
wijhierbeneden wrote:
| Quote: | Hello
Where can I find some info about the inner working of new/delete??
Is this compiler specific or defined by the standard??
|
The general behavior is defined by the standard in 3.7.3 that talks
about the allocation functions (operator new/delete) themselves,
5.3.4 and 5.3.5 which talk about the new/delete expressions themselves,
and of course 8.5 and 12.1 which talk about how initialization/consturctor
invocation occurs.
| Quote: | There is a lot
of info about the different malloc implementations but I can't find
anything about new.
|
The standard doesn't discuss the actual implentation of the allocation
deallocation function internals (just their interfaces) other than to
point out that they are designed to be able to be impelemented on top of
malloc/delete without much toil. In actuality, most implementations
do exactly that. Since they need to coexist with malloc, you have to
pretty much implement one in terms of the other or have them both call
a third common allocator.
|
|
| Back to top |
|
 |
David Lindauer Guest
|
Posted: Fri Oct 29, 2004 1:10 am Post subject: Re: new algorithm |
|
|
wijhierbeneden wrote:
| Quote: | Hello
Where can I find some info about the inner working of new/delete??
Is this compiler specific or defined by the standard?? There is a lot
of info about the different malloc implementations but I can't find
anything about new.
thx
|
the end results are defined by the standard, but the compiler has a
certain amount of leeway in implementation. Basically what you are
looking for new() is the equivalent of a call to malloc() (assuming you
are using the allocating new rather than the placement new) followed by
an invocation of an appropriate constructor if the object being allocated
has one. If the allocation fails, the user define new handler may be
called, and if that fails an exception may be thrown. If allocating an
array, a constructor is called for each element of the array as
appropriate. For delete, a destructor is called for the object (or each
object in the array) and then the space is freed.
David
|
|
| Back to top |
|
 |
wijhierbeneden Guest
|
Posted: Fri Oct 29, 2004 6:06 am Post subject: Re: new algorithm |
|
|
Ron Natalie <ron (AT) sensor (DOT) com> wrote
| Quote: | wijhierbeneden wrote:
Hello
Where can I find some info about the inner working of new/delete??
Is this compiler specific or defined by the standard??
The general behavior is defined by the standard in 3.7.3 that talks
about the allocation functions (operator new/delete) themselves,
5.3.4 and 5.3.5 which talk about the new/delete expressions themselves,
and of course 8.5 and 12.1 which talk about how initialization/consturctor
invocation occurs.
There is a lot
of info about the different malloc implementations but I can't find
anything about new.
The standard doesn't discuss the actual implentation of the allocation
deallocation function internals (just their interfaces) other than to
point out that they are designed to be able to be impelemented on top of
malloc/delete without much toil. In actuality, most implementations
do exactly that. Since they need to coexist with malloc, you have to
pretty much implement one in terms of the other or have them both call
a third common allocator.
|
Is there no info about the exact inner implementations available??
That is what i want, i want to know how the Virtual table is created
how the object is build on the heap, ...
That's why i need the inner working of new
There must be some info about that, no??
|
|
| Back to top |
|
 |
Gianni Mariani Guest
|
Posted: Fri Oct 29, 2004 6:26 am Post subject: Re: new algorithm |
|
|
wijhierbeneden wrote:
| Quote: | Ron Natalie <ron (AT) sensor (DOT) com> wrote
|
....
| Quote: |
Is there no info about the exact inner implementations available??
That is what i want, i want to know how the Virtual table is created
how the object is build on the heap, ...
That's why i need the inner working of new
There must be some info about that, no??
|
the new operator is associated with dynamically created objects only.
The compiler is responsible for dealing with how virtual functions and
auto objects are allocated. This almost certainly has nothing to do
with new.
|
|
| Back to top |
|
 |
Stuart Gerchick Guest
|
Posted: Fri Oct 29, 2004 9:40 am Post subject: Re: new algorithm |
|
|
[email]wijhierbeneden (AT) hotmail (DOT) com[/email] (wijhierbeneden) wrote in message news:<236f4e4.0410281142.26fccda4 (AT) posting (DOT) google.com>...
| Quote: | Hello
Where can I find some info about the inner working of new/delete??
Is this compiler specific or defined by the standard?? There is a lot
of info about the different malloc implementations but I can't find
anything about new.
thx
|
A good book for the inner workings of C++ is "Inside the C++ Object
Model" by Stanley Lippman
|
|
| Back to top |
|
 |
wijhierbeneden Guest
|
Posted: Fri Oct 29, 2004 1:17 pm Post subject: Re: new algorithm |
|
|
Gianni Mariani <gi2nospam (AT) mariani (DOT) ws> wrote
| Quote: | wijhierbeneden wrote:
Ron Natalie <ron (AT) sensor (DOT) com> wrote
...
Is there no info about the exact inner implementations available??
That is what i want, i want to know how the Virtual table is created
how the object is build on the heap, ...
That's why i need the inner working of new
There must be some info about that, no??
the new operator is associated with dynamically created objects only.
The compiler is responsible for dealing with how virtual functions and
auto objects are allocated. This almost certainly has nothing to do
with new.
|
But the pointer to the virtual table is located inside the object.
Doesn't new has to create the pointer (the place where it points to
can be chosen by the compiler).
|
|
| Back to top |
|
 |
Gianni Mariani Guest
|
Posted: Fri Oct 29, 2004 2:53 pm Post subject: Re: new algorithm |
|
|
wijhierbeneden wrote:
| Quote: | Gianni Mariani <gi2nospam (AT) mariani (DOT) ws> wrote
|
....
| Quote: | The compiler is responsible for dealing with how virtual functions and
auto objects are allocated. This almost certainly has nothing to do
with new.
But the pointer to the virtual table is located inside the object.
Doesn't new has to create the pointer (the place where it points to
can be chosen by the compiler).
|
The constructor has this responsibility.
|
|
| Back to top |
|
 |
Karl Heinz Buchegger Guest
|
Posted: Fri Oct 29, 2004 2:55 pm Post subject: Re: new algorithm |
|
|
wijhierbeneden wrote:
| Quote: |
Gianni Mariani <gi2nospam (AT) mariani (DOT) ws> wrote
wijhierbeneden wrote:
Ron Natalie <ron (AT) sensor (DOT) com> wrote
...
Is there no info about the exact inner implementations available??
That is what i want, i want to know how the Virtual table is created
how the object is build on the heap, ...
That's why i need the inner working of new
There must be some info about that, no??
the new operator is associated with dynamically created objects only.
The compiler is responsible for dealing with how virtual functions and
auto objects are allocated. This almost certainly has nothing to do
with new.
But the pointer to the virtual table is located inside the object.
Doesn't new has to create the pointer (the place where it points to
can be chosen by the compiler).
|
The purpose of new (if you write your own) is to get your
hands at some memory and return a pointer to it. For this new
is given the size of the requested memory. The details of
object construction in that memory are taken care of by the code
which calls new.
--
Karl Heinz Buchegger
[email]kbuchegg (AT) gascad (DOT) at[/email]
|
|
| Back to top |
|
 |
Markus Elfring Guest
|
|
| Back to top |
|
 |
Ron Natalie Guest
|
Posted: Fri Oct 29, 2004 7:29 pm Post subject: Re: new algorithm |
|
|
Gianni Mariani wrote:
| Quote: | wijhierbeneden wrote:
Gianni Mariani <gi2nospam (AT) mariani (DOT) ws> wrote in message
news:<jdmdnQMPWJs7fxzcRVn-jA (AT) speakeasy (DOT) net>...
...
The compiler is responsible for dealing with how virtual functions
and auto objects are allocated. This almost certainly has nothing to
do with new.
But the pointer to the virtual table is located inside the object.
Doesn't new has to create the pointer (the place where it points to
can be chosen by the compiler).
The constructor has this responsibility.
|
The C++ notion of the constructor DOES NOT. Implementations may
piggy back that initialization on the constructor linkage, but that's
just an impelementation detail.
|
|
| Back to top |
|
 |
E. Robert Tisdale Guest
|
Posted: Fri Oct 29, 2004 8:24 pm Post subject: Re: new algorithm |
|
|
Gianni Mariani wrote:
| Quote: | wijhierbeneden wrote:
Gianni Mariani wrote:
...
The compiler is responsible
for dealing with how virtual functions and auto objects are allocated.
This almost certainly has nothing to do with new.
But the pointer to the virtual table is located inside the object.
Doesn't new has to create the pointer
(the place where it points to can be chosen by the compiler).
The constructor has this responsibility.
cat C.h
#ifndef GUARD_C_H |
class C {
private:
// representation
int I;
// constructors
C(int i = 0);
virtual
~C(void);
};
#define GUARD_C_H
#endif//GUARD_C_H
| Quote: | cat C.cc
#include "C.h" |
C::C(int i): I(i) { }
C::~C(void) { }
| Quote: | g++ -Wall -ansi -pedantic -S C.cc
cat C.s
|
|
|
| Back to top |
|
 |
wijhierbeneden Guest
|
Posted: Sat Oct 30, 2004 9:11 am Post subject: Re: new algorithm |
|
|
Gianni Mariani <gi2nospam (AT) mariani (DOT) ws> wrote
| Quote: | wijhierbeneden wrote:
Gianni Mariani <gi2nospam (AT) mariani (DOT) ws> wrote
...
The compiler is responsible for dealing with how virtual functions and
auto objects are allocated. This almost certainly has nothing to do
with new.
But the pointer to the virtual table is located inside the object.
Doesn't new has to create the pointer (the place where it points to
can be chosen by the compiler).
The constructor has this responsibility.
|
Why can the compiler know where the pointer must point to??
This is determind at runtime. So new has to do this i assume.
|
|
| Back to top |
|
 |
John Harrison Guest
|
Posted: Sat Oct 30, 2004 10:10 am Post subject: Re: new algorithm |
|
|
"wijhierbeneden" <wijhierbeneden (AT) hotmail (DOT) com> wrote
| Quote: | Gianni Mariani <gi2nospam (AT) mariani (DOT) ws> wrote
wijhierbeneden wrote:
Gianni Mariani <gi2nospam (AT) mariani (DOT) ws> wrote
...
The compiler is responsible for dealing with how virtual functions and
auto objects are allocated. This almost certainly has nothing to do
with new.
But the pointer to the virtual table is located inside the object.
Doesn't new has to create the pointer (the place where it points to
can be chosen by the compiler).
The constructor has this responsibility.
Why can the compiler know where the pointer must point to??
This is determind at runtime. So new has to do this i assume.
|
Which pointer are you talking about? The constructor is responsible for
assigning the pointer to a virtual table. There is one virtual table for
each class, so it is easy for the compiler to assign this.
The pointer to the object itself is of course determined by new.
john
|
|
| Back to top |
|
 |
|