[fpc-pascal] dynamic array and new/dispose
Amit Bueno
amitbueno at gmail.com
Wed Feb 2 17:26:11 CET 2011
Seems that I found a workaround.
When calling the NewSubChunk in the following syntax:
SubChunks[NewSubChunk]^.read(fl); /// raise an exception.
While
MyIndex := NewSubChunk;
SubChunks[MyIndex]^.read(fl); /// raise an exception.
Doesn't raise any excetion….
Maybe the experts could say why, I don't know why…
Amit
From: fpc-pascal-bounces at lists.freepascal.org [mailto:fpc-pascal-bounces at lists.freepascal.org] On Behalf Of ik
Sent: Wednesday, February 02, 2011 5:48 PM
To: FPC-Pascal users discussions
Subject: Re: [fpc-pascal] dynamic array and new/dispose
I have created a proof of concept from your code:
----------------------------
{$mode delphi}
program test;
type
PChunk = ^Chunk;
Chunk = Object
SubChunks : array of PChunk;
data : Pointer;
Function NewSubchunk: integer;
end;
function Chunk.NewSubchunk :integer;
var
x : integer;
begin
x := High(SubChunks)+2;
setlength(SubChunks, x);
New(subchunks[x]);
SubChunks[x]^.Data := Self.Data;
Result := x;
end;
var
ac : Chunk;
begin
ac.data := PChar('Hello world');
writeln(ac.NewSubchunk);
end.
-----------------------
Does it work for you (I do not have any apple to test it on, but it works on my Linux) ?
And yes it leaks memory :)
Ido
LINESIP - Opening the source for communication
http://www.linesip.com
http://www.linesip.co.il
On Wed, Feb 2, 2011 at 17:29, Amit Bueno <amitbueno at gmail.com> wrote:
Of course it does -- otherwise it won't have worked on delphi under windows.
The X = High(SubChunks);
---
Amit
On Wed, Feb 2, 2011 at 5:27 PM, ik <idokan at gmail.com> wrote:
On Wed, Feb 2, 2011 at 17:18, Amit Bueno <amitbueno at gmail.com> wrote:
The SubChunks are -- 'var subchunks array of pchunk;' contained in chunk
before allocating the subchunks a setlength(subchunks, High(subchunks)+2) is called.
But does the X variable point to existed index in the array ? if not, then it explains the "access violation".
---
Amit
On Wed, Feb 2, 2011 at 5:15 PM, ik <idokan at gmail.com> wrote:
On Wed, Feb 2, 2011 at 16:57, Amit Bueno <amitbueno at gmail.com> wrote:
Seems that the ios doesn't allocated properly my objects,. after allocation when trying to run a function from the object it fails.
I tried replacing the New(subchunks[X]) to SubChunks[X] := AllocMem(sizeof(Chunk));
Again this works on the windows, it doesn't on the ios.
Have you got any ideas?
Does "X" actually exists as an index (I mean the value of it) ?
---
Amit
On Wed, Feb 2, 2011 at 3:34 PM, Amit Bueno <amitbueno at gmail.com> wrote:
Attached is the shrinked prof.rar file (481kb).
You can download it as well from:
http://bueno.co.il/files/prof.rar
---
Amit
-----Original Message-----
From: fpc-pascal-bounces at lists.freepascal.org
[mailto:fpc-pascal-bounces at lists.freepascal.org] On Behalf Of Jonas Maebe
Sent: Wednesday, February 02, 2011 3:28 PM
To: FPC-Pascal users discussions
Subject: Re: [fpc-pascal] dynamic array and new/dispose
On 02 Feb 2011, at 14:10, Amit Bueno wrote:
> Have you got the prof.rar?
No. I've just looked at the posts held for moderation and your mail is over
5MB. That is way too large to send to a mailing list. First of all, make
sure to only include source code, not compiled units, programs or resources.
Secondly, if it's that big, put it online on a website and only send the
link to the mailing list.
Jonas
_______________________________________________
fpc-pascal maillist - fpc-pascal at lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
_______________________________________________
fpc-pascal maillist - fpc-pascal at lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Ido
LINESIP - Opening the source for communication
http://www.linesip.com <http://www.linesip.com/>
http://www.linesip.co.il <http://www.linesip.co.il/>
_______________________________________________
fpc-pascal maillist - fpc-pascal at lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
_______________________________________________
fpc-pascal maillist - fpc-pascal at lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Ido
LINESIP - Opening the source for communication
http://www.linesip.com <http://www.linesip.com/>
http://www.linesip.co.il <http://www.linesip.co.il/>
_______________________________________________
fpc-pascal maillist - fpc-pascal at lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
_______________________________________________
fpc-pascal maillist - fpc-pascal at lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20110202/4abccbf8/attachment.html>
More information about the fpc-pascal
mailing list