Re: [fpc-pascal] How to free this memory and avoid memory leak

2009-10-08 Thread Jonas Maebe
On 08 Oct 2009, at 15:51, Graeme Geldenhuys wrote: procedure THelpFile.ReadContents; var Topic: TTopic; EntryIndex: longint; pEntry: pTTOCEntryStart; tocarray: array of Int32; p: PByte; begin _Topics.Capacity := _Header.ntoc; SetLength(tocarray, _Header.ntoc); p := _Data +

Re: [fpc-pascal] How to free this memory and avoid memory leak

2009-10-08 Thread Alexey Voytsehovich
Hello Graeme, Thursday, October 8, 2009, 4:51:34 PM, you wrote: tocarray: array of Int32; p: PByte; begin _Topics.Capacity := _Header.ntoc; SetLength(tocarray, _Header.ntoc); // Finalize(tocarray);--- doesn't work Finalize(tocarray, _header.ntoc);

Re: [fpc-pascal] How to free this memory and avoid memory leak

2009-10-08 Thread Vincent Snijders
Graeme Geldenhuys schreef: Hi, -- procedure THelpFile.ReadContents; var Topic: TTopic; EntryIndex: longint; pEntry: pTTOCEntryStart; tocarray: array of Int32; p: PByte; begin _Topics.Capacity := _Header.ntoc; SetLength(tocarray, _Header.ntoc);

Re: [fpc-pascal] How to free this memory and avoid memory leak

2009-10-08 Thread Jonas Maebe
On 08 Oct 2009, at 15:58, Alexey Voytsehovich wrote: Thursday, October 8, 2009, 4:51:34 PM, you wrote: // Finalize(tocarray);--- doesn't work Finalize(tocarray, _header.ntoc); --- doesn't work tocarray := nil; --- doesn't work

Re: [fpc-pascal] How to free this memory and avoid memory leak

2009-10-08 Thread Graeme Geldenhuys
2009/10/8 Jonas Maebe jonas.ma...@elis.ugent.be:  SetLength(tocarray, _Header.ntoc);  p := _Data + _Header.tocoffsetsstart;  Move(p, tocarray, SizeOf(tocarray)); This has to be move(p^, tocarray^, length(tocarray)*sizeof(tocarray[0])); ^ This gives a

Re: [fpc-pascal] How to free this memory and avoid memory leak

2009-10-08 Thread Andrew Brunner
     Move(p, tocarray[0], SizeOf(tocarray)); This causes an Access Violation at runtime. This should not cause as RAV. You must call SetLength(toarray,SizeOfMemory) and also don't use SizeOf(tocarray) use Length(tocarray)*SizeOf(What ever the element is))

Re: [fpc-pascal] How to free this memory and avoid memory leak

2009-10-08 Thread Graeme Geldenhuys
2009/10/8 Jonas Maebe jonas.ma...@elis.ugent.be: Also, as you can see the program does not really depend on the data being actually stored in a dynamic array. So you could just as well use tocarray: ^Int32 and assign it the value of p (as you pretty much did until now). Ah! That is what I

Re: [fpc-pascal] How to free this memory and avoid memory leak

2009-10-08 Thread Vincent Snijders
Graeme Geldenhuys schreef: 2009/10/8 Jonas Maebe jonas.ma...@elis.ugent.be: SetLength(tocarray, _Header.ntoc); p := _Data + _Header.tocoffsetsstart; Move(p, tocarray, SizeOf(tocarray)); This has to be move(p^, tocarray^, length(tocarray)*sizeof(tocarray[0]));

Re: [fpc-pascal] How to free this memory and avoid memory leak

2009-10-08 Thread Mattias Gärtner
Zitat von Graeme Geldenhuys graemeg.li...@gmail.com: [...] * ntoc = number of entries in the array. Each entry is a LongWord (or Int32 in the code below) * tocarray is my local array that gets populated with information from the file, using the Move() procedure. * tocoffsetsstart is the

Re: [fpc-pascal] How to free this memory and avoid memory leak

2009-10-08 Thread Jonas Maebe
On 08 Oct 2009, at 16:18, Graeme Geldenhuys wrote: 2009/10/8 Jonas Maebe jonas.ma...@elis.ugent.be: SetLength(tocarray, _Header.ntoc); p := _Data + _Header.tocoffsetsstart; Move(p, tocarray, SizeOf(tocarray)); This has to be move(p^, tocarray^, length(tocarray)*sizeof(tocarray[0]));

Re: [fpc-pascal] How to free this memory and avoid memory leak

2009-10-08 Thread Graeme Geldenhuys
2009/10/8 Vincent Snijders vsnijd...@vodafonevast.nl: Working with pointers, if you don't get it, maybe just use a loop. I have to admit. After working for so long with RDBMS API's, I got quite rusty with the more low level file reading, record structures and pointer arithmetic. Database

Re: [fpc-pascal] How to free this memory and avoid memory leak

2009-10-08 Thread Graeme Geldenhuys
2009/10/8 Jonas Maebe jonas.ma...@elis.ugent.be: Also with understanding how dynamic arrays and/or move work. Dynamic arrays are reference counted pointers to data blobs. sizeof(dynamic_array_var) = sizeof(pointer), always, and regardless of the length of the array. It's like sizeof(class) =