C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

new algorithm
Goto page 1, 2  Next
 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
wijhierbeneden
Guest





PostPosted: Thu Oct 28, 2004 7:42 pm    Post subject: new algorithm Reply with 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
Back to top
Victor Bazarov
Guest





PostPosted: Thu Oct 28, 2004 7:44 pm    Post subject: Re: new algorithm Reply with quote



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





PostPosted: Thu Oct 28, 2004 8:45 pm    Post subject: Re: new algorithm Reply with quote



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





PostPosted: Fri Oct 29, 2004 1:10 am    Post subject: Re: new algorithm Reply with quote



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





PostPosted: Fri Oct 29, 2004 6:06 am    Post subject: Re: new algorithm Reply with quote

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





PostPosted: Fri Oct 29, 2004 6:26 am    Post subject: Re: new algorithm Reply with quote

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





PostPosted: Fri Oct 29, 2004 9:40 am    Post subject: Re: new algorithm Reply with quote

[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





PostPosted: Fri Oct 29, 2004 1:17 pm    Post subject: Re: new algorithm Reply with quote

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





PostPosted: Fri Oct 29, 2004 2:53 pm    Post subject: Re: new algorithm Reply with quote

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





PostPosted: Fri Oct 29, 2004 2:55 pm    Post subject: Re: new algorithm Reply with quote

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





PostPosted: Fri Oct 29, 2004 7:01 pm    Post subject: Re: new algorithm Reply with quote

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.

Would you like to read this?
- Freestore management
http://www.fmi.uni-konstanz.de/~kuehl/c++-faq/freestore-mgmt.html

- Memory Management
http://gotw.ca/gotw/009.htm
http://gotw.ca/gotw/010.htm

- http://en.wikipedia.org/wiki/C_Plus_Plus

- http://en.wikipedia.org/wiki/Memory_allocation

- http://citeseer.ist.psu.edu/cis?q=malloc

- Discussion "memory allocation libraries for multithreaded
applications"
http://groups.google.de/groups?threadm=40ed1d8f.0301120549.4a4d400c%40posting.google.com

How do you think about to look at the sources of free compilers if you
are interested in implementation details?

Regards,
Markus

Back to top
Ron Natalie
Guest





PostPosted: Fri Oct 29, 2004 7:29 pm    Post subject: Re: new algorithm Reply with quote

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





PostPosted: Fri Oct 29, 2004 8:24 pm    Post subject: Re: new algorithm Reply with quote

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





PostPosted: Sat Oct 30, 2004 9:11 am    Post subject: Re: new algorithm Reply with quote

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





PostPosted: Sat Oct 30, 2004 10:10 am    Post subject: Re: new algorithm Reply with quote


"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
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.