Re: [Dev-C++] dynamic allocation and structs
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
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
|