Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2006-09

multidimensional dynarrays SetLenght and memory layout

3 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Marc Santhoff

Hi,

since I managed to get static arrays handed over to a C library I want to know if this is possible for dynamic arrays too.

I browsed the docs and source but I'm not able to find the actual implementation of the SetLength() procedure for dynarrays. Where is it or maybe better: how does it work?

I think I'll know when the first question is answered, but: how is the memory for dynamic arrays handled, is there a chance of forcing it to be one continuous block on the heap for giving a pointer to it to an external function?

TIA,
Marc

Reply by email

Florian Klaempfl
to Marc Santhoff
Show quoted text 7 lines
Hi, since I managed to get static arrays handed over to a C library I want to know if this is possible for dynamic arrays too. I browsed the docs and source but I'm not able to find the actual implementation of the SetLength() procedure for dynarrays.

rtl/inc/dynarr.inc

Show quoted text 7 lines
Where is it or maybe better: how does it work? I think I'll know when the first question is answered, but: how is the memory for dynamic arrays handled, is there a chance of forcing it to be one continuous block on the heap for giving a pointer to it to an external function?

No. Dyn. arrays involve several compiler magic. A dyn. array is basically a pointer to the real dyn. array containing size information and the data.

Show quoted text 8 lines
TIA, Marc _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply by email

Marc Santhoff
to Florian Klaempfl
Florian Klaempfl wrote 10 lines
Marc Santhoff schrieb: > Hi, > > since I managed to get static arrays handed over to a C library I want > to know if this is possible for dynamic arrays too. > > I browsed the docs and source but I'm not able to find the actual > implementation of the SetLength() procedure for dynarrays. rtl/inc/dynarr.inc

I had looked at that one, but didn't understand ...

Show quoted text 11 lines
> Where is it > or maybe better: how does it work? > > I think I'll know when the first question is answered, but: how is the > memory for dynamic arrays handled, is there a chance of forcing it to be > one continuous block on the heap for giving a pointer to it to an > external function? No. Dyn. arrays involve several compiler magic. A dyn. array is basically a pointer to the real dyn. array containing size information and the data.

... and that's the cause.

At least I know and can decide between forgetting about dynamic arrays or making an own implementation.

Thank you,
Marc

Reply by email