TIP: Click on subject to list as thread! ANSI
echo: nthelp
to: Antti Kurenniemi
from: John Beckett
date: 2004-11-09 09:27:58
subject: Re: C++

From: John Beckett 

"Antti Kurenniemi"  wrote in
message news::
> One thing at least is, that with "int", you're reserving
exactly the amount
> of memory that the "int" needs, and it will be scraped off
once the variable
> goes out of scope, but for an object of type "date" you're
automatically
> only reserving as much memory as goes to a memory pointer (your
"Date a"
> actually only creates a pointer to an object in memory, and the object
> itself handles it's own memory allocations - it can use however much of
> memory if it wants to, and you'll never really know it unless you read the
> code / debug it). You'll have to destroy the object after you're done with
> it to make sure that not only your pointer to that object in memory is
> released when it goes out of scope but also whatever the object did.

In case Geo reads this literally, I think it should be clarified. Consider:

void func()
{
    int i;
    Date d;
    // ... do stuff ...
}

It's not true that the above creates a pointer to the Date. Also, rather
than say that you have to destroy d after you're finished with it, I would
say that the compiler will call the destructor for d when d goes out of
scope (when the function returns). The designer of Date only has to make
sure that the destructor does whatever is required to clean up, if
anything.

You're discussing a common situation where the internal implementation of
the class allocates some new memory and assign its address to a pointer in
the object. In that case, The variable d could be quite small (say just big
enough to hold a pointer), but there could be lots of data referenced by d.

John

--- BBBS/NT v4.01 Flag-5
* Origin: Barktopia BBS Site http://HarborWebs.com:8081 (1:379/45)
SEEN-BY: 633/267 270 5030/786
@PATH: 379/45 1 396/45 106/2000 633/267

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.