Thread: Re: [Dev-C++] dynamic allocation and structs
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Daniel G. <sp...@ho...> - 2002-10-24 12:29:03
|
I can help with the first - the lifetime of a variable created with malloc()
is forever - until you call free() of course!
>From: "Scott Williams" <se...@al...>
>Reply-To: <se...@al...>
>To: <dev...@li...>
>Subject: [Dev-C++] dynamic allocation and structs
>Date: Thu, 24 Oct 2002 08:18:24 -0400
>
>Hi,
>
>I'm working in C (no C++ please). Got a couple of questions related to
>dynamic allocation and in particular, dynamically allocating an array of
>structs.
>
>First, what is the duration of memory allocated by malloc (etc.)? In
>particular, I want to dynamically allocate/de-allocate several global
>variables within a single subroutine called from main and so want to be
>sure
>that the allocated memory exists beyond the scope of that subroutine.
>
>Second, it is my understanding that it is perfectly acceptable to have an
>array of structs. E.g.,
>
>struct mystruct {
> double var1;
> long var2;
> etc...
>}
>
>. . .
>
>struct mystruct data[100];
>
>Is this correct? If so, what then is the calling sequence to dynamically
>allocate an array of structs, and, in particularly, make the result
>available globally?
>
>Thanks for your help (& sorry if this is naive).
>
>Scott Williams
>
>
>
>-------------------------------------------------------
>This sf.net email is sponsored by: Influence the future
>of Java(TM) technology. Join the Java Community
>Process(SM) (JCP(SM)) program now.
>http://ad.doubleclick.net/clk;4729346;7592162;s?http://www.sun.com/javavote
>_______________________________________________
>Dev-cpp-users mailing list
>Dev...@li...
>TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm
>https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
_________________________________________________________________
Surf the Web without missing calls! Get MSN Broadband.
http://resourcecenter.msn.com/access/plans/freeactivation.asp
|
|
From: Ioannis V. <no...@ho...> - 2002-10-25 09:43:58
|
> -----Original Message----- > From: Ioannis Vranos [mailto:no...@ho...] > Sent: Friday, October 25, 2002 12:39 PM > To: Dev-C++ Mailing List (dev...@li...) > Subject: RE: [Dev-C++] dynamic allocation and structs > > > > -----Original Message----- > > From: Per Westermark [mailto:pw...@ia...] > > Sent: Friday, October 25, 2002 11:51 AM > > To: Ioannis Vranos > > Cc: 'Dev-C++ Mailing List' > > Subject: RE: [Dev-C++] dynamic allocation and structs > > > > > > The trick is that vector isn't programming. It is a standard > > - and very > > old - mathematical term for a one-dimensional matrix. > > > Yes, but when we speak of C++ code, calling a built in array > a "vector" can only be confusing. > > > > > There has been > > millions of vector implementations before STL did a template > > version, and > > the probability of a finding a STL construct in a C program > > is not that > > high :-) > > > Yes, but it still can be confusing to C++ programmers. > > > > > > > While code might syntactically switch around between > > (*a).x, > > a->x > > a[0].x > > > > the third form is definitely dangerous to use when a is only > > a pointer to > > a single element. If there is an element zero, the logical > > conclusion is > > that there must be a element one. > > > Yes, if there is only one element i would use the -> only. > When we have more the [] is more suitable. Both are valid. Also i cannot understand why someone would create a single dimensional array of pointers on the free store and then assign an element on the free store to each of them. It's a total waste of everything. :) Using a simple pointer and allocating space for the elements directly on the free store would be a reasonable thing to do. /* Array of 100 mystructs on the free store */ struct mystruct *p=malloc(100*sizeof(*p)); Ioannis * Ioannis Vranos * Programming pages: http://www.noicys.freeurl.com * Alternative URL: http://run.to/noicys |
|
From: Per W. <pw...@ia...> - 2002-10-25 10:54:19
|
Exactly why my previous mail specified use-cases. - Sparse matrix, where a lot of entries are NULL. - Quick sort, since it's enough to move the pointers. - Different object types for each index, simulating C++ abstract base class. - Supports large vector in 16-bit code, where it's possible to have 16000 entries of up to 64000 byte size each. /Per W On Fri, 25 Oct 2002, Ioannis Vranos wrote: > > -----Original Message----- > > From: Ioannis Vranos [mailto:no...@ho...] > > Sent: Friday, October 25, 2002 12:39 PM > > To: Dev-C++ Mailing List (dev...@li...) > > Subject: RE: [Dev-C++] dynamic allocation and structs > > > > > > > -----Original Message----- > > > From: Per Westermark [mailto:pw...@ia...] > > > Sent: Friday, October 25, 2002 11:51 AM > > > To: Ioannis Vranos > > > Cc: 'Dev-C++ Mailing List' > > > Subject: RE: [Dev-C++] dynamic allocation and structs > > > > > > > > > The trick is that vector isn't programming. It is a standard > > > - and very > > > old - mathematical term for a one-dimensional matrix. > > > > > > Yes, but when we speak of C++ code, calling a built in array > > a "vector" can only be confusing. > > > > > > > > > There has been > > > millions of vector implementations before STL did a template > > > version, and > > > the probability of a finding a STL construct in a C program > > > is not that > > > high :-) > > > > > > Yes, but it still can be confusing to C++ programmers. > > > > > > > > > > > > While code might syntactically switch around between > > > (*a).x, > > > a->x > > > a[0].x > > > > > > the third form is definitely dangerous to use when a is only > > > a pointer to > > > a single element. If there is an element zero, the logical > > > conclusion is > > > that there must be a element one. > > > > > > Yes, if there is only one element i would use the -> only. > > When we have more the [] is more suitable. Both are valid. > > Also i cannot understand why someone would create a single dimensional > array of pointers on the free store and then assign an element on the > free store to each of them. It's a total waste of everything. :) Using a > simple pointer and allocating space for the elements directly on the > free store would be a reasonable thing to do. > > /* Array of 100 mystructs on the free store */ > struct mystruct *p=malloc(100*sizeof(*p)); > > > > Ioannis > > * Ioannis Vranos > * Programming pages: http://www.noicys.freeurl.com > * Alternative URL: http://run.to/noicys > > > ------------------------------------------------------- > This sf.net email is sponsored by: Influence the future > of Java(TM) technology. Join the Java Community > Process(SM) (JCP(SM)) program now. > http://ads.sourceforge.net/cgi-bin/redirect.pl?sunm0004en > _______________________________________________ > Dev-cpp-users mailing list > Dev...@li... > TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > |
|
From: Ioannis V. <no...@ho...> - 2002-10-25 13:08:56
|
> -----Original Message----- > From: Per Westermark [mailto:pw...@ia...] > Sent: Friday, October 25, 2002 1:54 PM > To: Ioannis Vranos > Cc: Dev-C++ Mailing List > Subject: RE: [Dev-C++] dynamic allocation and structs > > > Exactly why my previous mail specified use-cases. > > - Sparse matrix, where a lot of entries are NULL. > - Quick sort, since it's enough to move the pointers. > - Different object types for each index, simulating C++ abstract base > class. You need void * for this (or a container struct). But this means you can't use it directly. > - Supports large vector in 16-bit code, where it's possible > to have 16000 > entries of up to 64000 byte size each. Yep, you are an older programmer than me. :) I know the 64 KB DOS limit though. Ioannis * Ioannis Vranos * Programming pages: http://www.noicys.freeurl.com * Alternative URL: http://run.to/noicys |
|
From: Per W. <pw...@ia...> - 2002-10-25 15:45:45
|
Either store void pointers in the array, or always typecast each array assignment to a "base-class" struct. Since C doesn't have any RTTI, the simplest way to afterwards find out about the contents of the pointer, is to assure that all used structs always starts with a field type, that may be checked, before typecasting the pointer to the correct type and do any real actions. /Per W On Fri, 25 Oct 2002, Ioannis Vranos wrote: > > -----Original Message----- > > From: Per Westermark [mailto:pw...@ia...] > > Sent: Friday, October 25, 2002 1:54 PM > > To: Ioannis Vranos > > Cc: Dev-C++ Mailing List > > Subject: RE: [Dev-C++] dynamic allocation and structs > > > > > > Exactly why my previous mail specified use-cases. > > > > - Sparse matrix, where a lot of entries are NULL. > > - Quick sort, since it's enough to move the pointers. > > - Different object types for each index, simulating C++ abstract base > > class. > > > You need void * for this (or a container struct). But this means you > can't use it directly. > > > > - Supports large vector in 16-bit code, where it's possible > > to have 16000 > > entries of up to 64000 byte size each. > > > Yep, you are an older programmer than me. :) I know the 64 KB DOS limit > though. > > > Ioannis > > * Ioannis Vranos > * Programming pages: http://www.noicys.freeurl.com > * Alternative URL: http://run.to/noicys > > > ------------------------------------------------------- > This sf.net email is sponsored by: Influence the future > of Java(TM) technology. Join the Java Community > Process(SM) (JCP(SM)) program now. > http://ads.sourceforge.net/cgi-bin/redirect.pl?sunm0004en > _______________________________________________ > Dev-cpp-users mailing list > Dev...@li... > TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > |
|
From: Ioannis V. <no...@ho...> - 2002-10-25 13:15:47
|
> -----Original Message----- > From: dev...@li... > [mailto:dev...@li...] On Behalf > Of Per Westermark > Sent: Friday, October 25, 2002 1:54 PM > To: Ioannis Vranos > Cc: Dev-C++ Mailing List > Subject: RE: [Dev-C++] dynamic allocation and structs > > > Exactly why my previous mail specified use-cases. > > - Sparse matrix, where a lot of entries are NULL. > - Quick sort, since it's enough to move the pointers. As far as i can think of it, you can't use qsort() though. qsort() copies the elements and in addition, you can't compare pointers not pointing inside the same array. So you have to define your own facilities. Ioannis * Ioannis Vranos * Programming pages: http://www.noicys.freeurl.com * Alternative URL: http://run.to/noicys |
|
From: Per W. <pw...@ia...> - 2002-10-25 14:06:29
|
On Fri, 25 Oct 2002, Ioannis Vranos wrote: > > -----Original Message----- > > From: dev...@li... > > [mailto:dev...@li...] On Behalf > > Of Per Westermark > > Sent: Friday, October 25, 2002 1:54 PM > > To: Ioannis Vranos > > Cc: Dev-C++ Mailing List > > Subject: RE: [Dev-C++] dynamic allocation and structs > > > > > > Exactly why my previous mail specified use-cases. > > > > - Sparse matrix, where a lot of entries are NULL. > > - Quick sort, since it's enough to move the pointers. > > > As far as i can think of it, you can't use qsort() though. qsort() > copies the elements and in addition, you can't compare pointers not > pointing inside the same array. So you have to define your own > facilities. As already posted, a compilable example with qsort. qsort think the pointers are the elements, so the sort isn't a problem. All you have to think about in your compare function, is that you don't get pointers to your elements, but pointers to pointers to your elements. > > > Ioannis > > * Ioannis Vranos > * Programming pages: http://www.noicys.freeurl.com > * Alternative URL: http://run.to/noicys > > > > > ------------------------------------------------------- > This sf.net email is sponsored by: Influence the future > of Java(TM) technology. Join the Java Community > Process(SM) (JCP(SM)) program now. > http://ads.sourceforge.net/cgi-bin/redirect.pl?sunm0004en > _______________________________________________ > Dev-cpp-users mailing list > Dev...@li... > TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > |
|
From: Ioannis V. <no...@ho...> - 2002-10-25 14:09:44
|
> -----Original Message----- > From: Per Westermark [mailto:pw...@ia...] > Sent: Friday, October 25, 2002 5:06 PM > To: Ioannis Vranos > Cc: 'Dev-C++ Mailing List' > Subject: RE: [Dev-C++] dynamic allocation and structs > > As already posted, a compilable example with qsort. > qsort think the pointers are the elements, so the sort isn't > a problem. > All you have to think about in your compare function, is that > you don't > get pointers to your elements, but pointers to pointers to > your elements. (On second thought) You are right. :) This is what usually happens in C++ with list when sort(). In this way you have rapid copying when dealing with large struct objects. C00l. Ioannis * Ioannis Vranos * Programming pages: http://www.noicys.freeurl.com * Alternative URL: http://run.to/noicys |
|
From: Per W. <pw...@ia...> - 2002-10-24 12:51:06
|
Well, maybe not directly forever.
It will also be automatically released - for most operating systems, that
is - when the application ends.
/Per W
On Thu, 24 Oct 2002, Daniel Glenfield wrote:
> I can help with the first - the lifetime of a variable created with mallo=
c()=20
> is forever - until you call free() of course!
>=20
>=20
>=20
>=20
> >From: "Scott Williams" <se...@al...>
> >Reply-To: <se...@al...>
> >To: <dev...@li...>
> >Subject: [Dev-C++] dynamic allocation and structs
> >Date: Thu, 24 Oct 2002 08:18:24 -0400
> >
> >Hi,
> >
> >I'm working in C (no C++ please). Got a couple of questions related to
> >dynamic allocation and in particular, dynamically allocating an array of
> >structs.
> >
> >First, what is the duration of memory allocated by malloc (etc.)? In
> >particular, I want to dynamically allocate/de-allocate several global
> >variables within a single subroutine called from main and so want to be=
=20
> >sure
> >that the allocated memory exists beyond the scope of that subroutine.
> >
> >Second, it is my understanding that it is perfectly acceptable to have a=
n
> >array of structs. E.g.,
> >
> >struct mystruct {
> > double var1;
> > long var2;
> > etc...
> >}
> >
> >. . .
> >
> >struct mystruct data[100];
> >
> >Is this correct? If so, what then is the calling sequence to dynamicall=
y
> >allocate an array of structs, and, in particularly, make the result
> >available globally?
> >
> >Thanks for your help (& sorry if this is naive).
> >
> >Scott Williams
> >
> >
> >
> >-------------------------------------------------------
> >This sf.net email is sponsored by: Influence the future
> >of Java(TM) technology. Join the Java Community
> >Process(SM) (JCP(SM)) program now.
> >http://ad.doubleclick.net/clk;4729346;7592162;s?http://www.sun.com/javav=
ote
> >_______________________________________________
> >Dev-cpp-users mailing list
> >Dev...@li...
> >TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm
> >https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>=20
>=20
> _________________________________________________________________
> Surf the Web without missing calls!=A0Get MSN Broadband. =20
> http://resourcecenter.msn.com/access/plans/freeactivation.asp
>=20
>=20
>=20
> -------------------------------------------------------
> This sf.net email is sponsored by: Influence the future=20
> of Java(TM) technology. Join the Java Community=20
> Process(SM) (JCP(SM)) program now.=20
> http://ad.doubleclick.net/clk;4729346;7592162;s?http://www.sun.com/javavo=
te
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>=20
|
|
From: Carlos d. M. <cg...@wo...> - 2002-10-24 14:27:52
|
Per Westermark escribi=F3:
> Well, maybe not directly forever.
>
> It will also be automatically released - for most operating systems, th=
at
> is - when the application ends.
Or when exiting the scope.
>
>
> /Per W
>
> On Thu, 24 Oct 2002, Daniel Glenfield wrote:
>
> > I can help with the first - the lifetime of a variable created with m=
alloc()
> > is forever - until you call free() of course!
> >
> >
> >
> >
> > >From: "Scott Williams" <se...@al...>
> > >Reply-To: <se...@al...>
> > >To: <dev...@li...>
> > >Subject: [Dev-C++] dynamic allocation and structs
> > >Date: Thu, 24 Oct 2002 08:18:24 -0400
> > >
> > >Hi,
> > >
> > >I'm working in C (no C++ please). Got a couple of questions related=
to
> > >dynamic allocation and in particular, dynamically allocating an arra=
y of
> > >structs.
> > >
> > >First, what is the duration of memory allocated by malloc (etc.)? I=
n
> > >particular, I want to dynamically allocate/de-allocate several globa=
l
> > >variables within a single subroutine called from main and so want to=
be
> > >sure
> > >that the allocated memory exists beyond the scope of that subroutine=
=2E
> > >
> > >Second, it is my understanding that it is perfectly acceptable to ha=
ve an
> > >array of structs. E.g.,
> > >
> > >struct mystruct {
> > > double var1;
> > > long var2;
> > > etc...
> > >}
> > >
> > >. . .
> > >
> > >struct mystruct data[100];
> > >
> > >Is this correct? If so, what then is the calling sequence to dynami=
cally
> > >allocate an array of structs, and, in particularly, make the result
> > >available globally?
> > >
> > >Thanks for your help (& sorry if this is naive).
> > >
> > >Scott Williams
> > >
> > >
> > >
> > >-------------------------------------------------------
> > >This sf.net email is sponsored by: Influence the future
> > >of Java(TM) technology. Join the Java Community
> > >Process(SM) (JCP(SM)) program now.
> > >http://ad.doubleclick.net/clk;4729346;7592162;s?http://www.sun.com/j=
avavote
> > >_______________________________________________
> > >Dev-cpp-users mailing list
> > >Dev...@li...
> > >TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm
> > >https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
> >
> >
> > _________________________________________________________________
> > Surf the Web without missing calls! Get MSN Broadband.
> > http://resourcecenter.msn.com/access/plans/freeactivation.asp
> >
> >
> >
> > -------------------------------------------------------
> > This sf.net email is sponsored by: Influence the future
> > of Java(TM) technology. Join the Java Community
> > Process(SM) (JCP(SM)) program now.
> > http://ad.doubleclick.net/clk;4729346;7592162;s?http://www.sun.com/ja=
vavote
> > _______________________________________________
> > Dev-cpp-users mailing list
> > Dev...@li...
> > TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm
> > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
> >
>
> -------------------------------------------------------
> This sf.net email is sponsored by: Influence the future
> of Java(TM) technology. Join the Java Community
> Process(SM) (JCP(SM)) program now.
> http://ad.doubleclick.net/clk;4729346;7592162;s?http://www.sun.com/java=
vote
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
|
|
From: Per W. <pw...@ia...> - 2002-10-24 14:46:38
|
Nope! Dyanmically allocated memory doesn't get released just because you leave the scope. An object destructor will - if correctly written - release memory allocted within the object, when the object goes out of scope. However, normal pointers doesn't have any destructors, so there will be no release of the memory. It will be the normal memory leak, i.e. a pointer no longer possible to access, that will not be released until the program ends, since unextended C++ doesn't have garbage collection. The only ways to release dynamically allocated memory is to: - manually releasing it - ending the program A destructor releasing local data from an object must be considered a =20 manual release, since the code specifically has to write a call to free() or delete. Yes, template-based containers can automatically release memory for the objects in the container, but only if the container destructor is called. If the container was created dynamically, the container will never get out of scope, so the destroctor won't run unless container is manually released... It is possible to create "smart pointers", i.e. a c++ object that looks and behaves like a pointer, but has a destructor that will release the memory when the "smart pointer" goes out of scope. Still, same thing as with template-based containers. If the "smart pointer" object is created dynamically, it won't go out of scope, and the destructor won't be called. /Per W EMA System email: pw...@ia... Per Westermark web: http://iapetus.neab.net Vargvaegen 174B phone: +46 8 410 17 198 S-906 42 Umeaa Sweden On Thu, 24 Oct 2002, Carlos Garc=EDa del Monte wrote: >=20 >=20 > Per Westermark escribi=F3: >=20 > > Well, maybe not directly forever. > > > > It will also be automatically released - for most operating systems, th= at > > is - when the application ends. >=20 > Or when exiting the scope. >=20 > > > > > > /Per W > > > > On Thu, 24 Oct 2002, Daniel Glenfield wrote: > > > > > I can help with the first - the lifetime of a variable created with m= alloc() > > > is forever - until you call free() of course! > > > > > > > > > > > > > > > >From: "Scott Williams" <se...@al...> > > > >Reply-To: <se...@al...> > > > >To: <dev...@li...> > > > >Subject: [Dev-C++] dynamic allocation and structs > > > >Date: Thu, 24 Oct 2002 08:18:24 -0400 > > > > > > > >Hi, > > > > > > > >I'm working in C (no C++ please). Got a couple of questions related= to > > > >dynamic allocation and in particular, dynamically allocating an arra= y of > > > >structs. > > > > > > > >First, what is the duration of memory allocated by malloc (etc.)? I= n > > > >particular, I want to dynamically allocate/de-allocate several globa= l > > > >variables within a single subroutine called from main and so want to= be > > > >sure > > > >that the allocated memory exists beyond the scope of that subroutine= =2E > > > > > > > >Second, it is my understanding that it is perfectly acceptable to ha= ve an > > > >array of structs. E.g., > > > > > > > >struct mystruct { > > > > double var1; > > > > long var2; > > > > etc... > > > >} > > > > > > > >. . . > > > > > > > >struct mystruct data[100]; > > > > > > > >Is this correct? If so, what then is the calling sequence to dynami= cally > > > >allocate an array of structs, and, in particularly, make the result > > > >available globally? > > > > > > > >Thanks for your help (& sorry if this is naive). > > > > > > > >Scott Williams > > > > > > > > > > > > > > > >------------------------------------------------------- > > > >This sf.net email is sponsored by: Influence the future > > > >of Java(TM) technology. Join the Java Community > > > >Process(SM) (JCP(SM)) program now. > > > >http://ad.doubleclick.net/clk;4729346;7592162;s?http://www.sun.com/j= avavote > > > >_______________________________________________ > > > >Dev-cpp-users mailing list > > > >Dev...@li... > > > >TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm > > > >https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > > > > > > > > > _________________________________________________________________ > > > Surf the Web without missing calls! Get MSN Broadband. > > > http://resourcecenter.msn.com/access/plans/freeactivation.asp > > > > > > > > > > > > ------------------------------------------------------- > > > This sf.net email is sponsored by: Influence the future > > > of Java(TM) technology. Join the Java Community > > > Process(SM) (JCP(SM)) program now. > > > http://ad.doubleclick.net/clk;4729346;7592162;s?http://www.sun.com/ja= vavote > > > _______________________________________________ > > > Dev-cpp-users mailing list > > > Dev...@li... > > > TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm > > > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > > > > > > > ------------------------------------------------------- > > This sf.net email is sponsored by: Influence the future > > of Java(TM) technology. Join the Java Community > > Process(SM) (JCP(SM)) program now. > > http://ad.doubleclick.net/clk;4729346;7592162;s?http://www.sun.com/java= vote > > _______________________________________________ > > Dev-cpp-users mailing list > > Dev...@li... > > TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm > > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users >=20 >=20 >=20 > ------------------------------------------------------- > This sf.net email is sponsored by: Influence the future > of Java(TM) technology. Join the Java Community > Process(SM) (JCP(SM)) program now. > http://ad.doubleclick.net/clk;4729346;7592162;s?http://www.sun.com/javavo= te > _______________________________________________ > Dev-cpp-users mailing list > Dev...@li... > TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users >=20 |
|
From: Ioannis V. <no...@ho...> - 2002-10-24 20:58:43
|
> -----Original Message----- > From: dev...@li...=20 > [mailto:dev...@li...] On Behalf=20 > Of Carlos Garc=A6=CDa del Monte > Sent: Thursday, October 24, 2002 5:26 PM > To: dev-cpp-users-list > Subject: Re: [Dev-C++] dynamic allocation and structs >=20 >=20 >=20 >=20 > Per Westermark escribi=A8=AE: >=20 > > Well, maybe not directly forever. > > > > It will also be automatically released - for most operating=20 > systems, that > > is - when the application ends. >=20 > Or when exiting the scope. No. Ioannis * Ioannis Vranos * Programming pages: http://www.noicys.freeurl.com * Alternative URL: http://run.to/noicys |
|
From: Per W. <pw...@ia...> - 2002-10-24 21:12:13
|
Answer is still yes. The question was: When will the memory be released. It will for just about all operating systems be released on termination of the program. If it wasn't, you would leak global memory in your computer, if you stop a program while debugging it, or if you manually kill the program. The destructor for all allocated objects will not be called, but that=20 wasn't the question. The memory will be released! /Per W On Thu, 24 Oct 2002, Ioannis Vranos wrote: > > -----Original Message----- > > From: dev...@li...=20 > > [mailto:dev...@li...] On Behalf=20 > > Of Carlos Garc=A6=CDa del Monte > > Sent: Thursday, October 24, 2002 5:26 PM > > To: dev-cpp-users-list > > Subject: Re: [Dev-C++] dynamic allocation and structs > >=20 > >=20 > >=20 > >=20 > > Per Westermark escribi=A8=AE: > >=20 > > > Well, maybe not directly forever. > > > > > > It will also be automatically released - for most operating=20 > > systems, that > > > is - when the application ends. > >=20 > > Or when exiting the scope. >=20 >=20 > No. >=20 >=20 > Ioannis >=20 > * Ioannis Vranos > * Programming pages: http://www.noicys.freeurl.com > * Alternative URL: http://run.to/noicys >=20 >=20 >=20 >=20 > ------------------------------------------------------- > This sf.net email is sponsored by: Influence the future > of Java(TM) technology. Join the Java Community > Process(SM) (JCP(SM)) program now. > http://ads.sourceforge.net/cgi-bin/redirect.pl?sunm0003en > _______________________________________________ > Dev-cpp-users mailing list > Dev...@li... > TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users >=20 |
|
From: Ioannis V. <no...@ho...> - 2002-10-24 21:19:52
|
> -----Original Message----- > From: Per Westermark [mailto:pw...@ia...] > Sent: Friday, October 25, 2002 12:12 AM > To: Ioannis Vranos > Cc: 'dev-cpp-users-list' > Subject: RE: [Dev-C++] dynamic allocation and structs > > > Answer is still yes. > > The question was: When will the memory be released. > It will for just about all operating systems be released on > termination > of the program. If it wasn't, you would leak global memory in your > computer, if you stop a program while debugging it, or if you manually > kill the program. > > The destructor for all allocated objects will not be called, but that > wasn't the question. The memory will be released! The "No" was for: "Or when exiting the scope." (that probably somebody else wrote). Ioannis * Ioannis Vranos * Programming pages: http://www.noicys.freeurl.com * Alternative URL: http://run.to/noicys |
|
From: Per W. <pw...@ia...> - 2002-10-24 22:03:13
|
Amen brother :-) /Per W On Fri, 25 Oct 2002, Ioannis Vranos wrote: > > -----Original Message----- > > From: Per Westermark [mailto:pw...@ia...] > > Sent: Friday, October 25, 2002 12:12 AM > > To: Ioannis Vranos > > Cc: 'dev-cpp-users-list' > > Subject: RE: [Dev-C++] dynamic allocation and structs > > > > > > Answer is still yes. > > > > The question was: When will the memory be released. > > It will for just about all operating systems be released on > > termination > > of the program. If it wasn't, you would leak global memory in your > > computer, if you stop a program while debugging it, or if you manually > > kill the program. > > > > The destructor for all allocated objects will not be called, but that > > wasn't the question. The memory will be released! > > > The "No" was for: "Or when exiting the scope." (that probably somebody > else wrote). > > > Ioannis > > * Ioannis Vranos > * Programming pages: http://www.noicys.freeurl.com > * Alternative URL: http://run.to/noicys > > > ------------------------------------------------------- > This sf.net email is sponsored by: Influence the future > of Java(TM) technology. Join the Java Community > Process(SM) (JCP(SM)) program now. > http://ads.sourceforge.net/cgi-bin/redirect.pl?sunm0003en > _______________________________________________ > Dev-cpp-users mailing list > Dev...@li... > TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > |