[fpc-pascal] allocating memory for records

Leonardo M. Ram� martinrame at yahoo.com
Fri Jul 7 19:09:48 CEST 2006


Marc,
you don't need to allocate memory for records, you can us as follows:

type
  MyRec = record
    a: integer; /* very clear */
    b: string; /* not clear, how much bytes are needed? */
  end;

var
  myRecVar: MyRec;

begin
  myRecVar.a := 10;
  myRecVar.b := 'Hello World!';
end;


--- Vincent Snijders <vsnijders at quicknet.nl> wrote:

> Marc Santhoff wrote:
> > Hi,
> > 
> > excuse me for asking dumb questions, but over using objects only for
> > years I forgot:
> > 
> > If I need to allocate memory for a record type variable, what functions
> > should get used?
> > 
> > Is the GetMem/FreeMem pair okay or is there something more appropriate?
> > 
> > var
> >   x: PMyRec
> > begin
> >   GetMem(x, sizeof(x));
> > 
> > would be my best guess atm.
> > 
> > 
> > 
> > And another related question:
> > 
> > If a record has a String field, how is memory allacation handled?
> > 
> > MyRec = record
> > 	a: integer; /* very clear */
> > 	b: string; /* not clear, how much bytes are needed? */
> > end;
> > 
> > 
> 
> I would use:
>    new(x);
> and
>    dispose(x);
> 
> I guess the memory will initialized and finalized for strings correctly 
> in that case too, but I am not sure;
> 
> Vincent.
> _______________________________________________
> fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
> 


Leonardo M. Ramé
http://leonardorame.blogspot.com

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 



More information about the fpc-pascal mailing list