Claudio Lo Gaffo
clogaffo at gmail.com
Tue May 24 23:28:41 CEST 2011
El 24/05/2011 03:57 p.m., Luis Fernando Del Aguila Mejía escribió:
>>> I'm surprised this compiles at all.
> Ok, Does my program does not compile on your computer ?
>>> You're mixing up manual allocation of memory on the heap for variables
>>> such as arrays with compiler allocation of heap memory for ansistrings
>>> (which are reference counted and deallocated automatically).
> Yes something like that. I'm trying to emulate something like
> VarLCad = array[0..2] of ansistring;
> But using GetMem(LCad,4*3) for the array. (4 bytes for the ansistring
> This can be done with: TList. But I write these simple programs, to
> know how compiler works.
> fpc-pascal maillist - fpc-pascal at lists.freepascal.org
You don't explain what is exactly the error you're getting but getmem
don't initialize the memory allocated, and when you assign a pointer to
ansistring the compiler decrements the reference counter of the
pointer's current value, if isn't nil. Since you have garbage in the
pointer, you'll get an access violation. If you don't get it, somewhere
the memory becomes corrupted. Sorry by my english, I expect you
More information about the fpc-pascal