Reference Issue

done.

  1. change: “TArray = record” to “TArray = class” => internal error

  2. Add this line: "f_first := ^TBlock(c_rtl.malloc(SIZE * cnt));"
    it raises an exception, ofc, because f_first is nil and next line I try to deref it

reproduced the first; the second fails with c_rtl not found, and SIZE being a type ref.

Fixe the first too btw.

1 Like

dont forget to add the c_rtl.fx in your RemObjects binary folder^^

Hmm, one question, if I cant bring the c_rtl.malloca(…) to work, because i am not so profound to implement such deep things underthehood, would you maybe consider the effort to bring this function to ExternalCalls.Malloca(…)

I tried to do it by my own, but I see now how much #defines he makes use of that I dont have the time to trace them all back to nirvana.

Just to be clear, what do you think this code will do (presuming it worked)

constructor TArray<T>(const cnt: TMaxCapacity);
begin
  f_first := ^TBlock<T>(alloca(15 * cnt));
...

?

It should give me the Adresse of the first block of an array of TBlock in the stack, and the whole Array lives on the stack, i wanted that to use as a backing buffer later on for bitmap(s)

And that the whole array is valuetype and gets copied when u assign a new instance of it:

Except that’s not how alloca works. It allocates it in the current functions stack. Which ends at the end of the array constructor. By the time you get it it’s lifetime is over.

1 Like

Ahhh, ok: do you know a function, where I can get a pointer to a long-lived array in the stack, where the actuall items lives as long the “TArray(record)” lives?

That’s not possible on the stack not with a dynamic nr of bytes. What is possible and what c++ often does Is have a value type that manages a heap allocated array. And frees it on finalization. You can ofc also do this in island with malloc and free.

Ah yes, and this is RAII - model I guess :wink:

And is the GC involved in this somehow, because he should trace the heap-allocated-objects for deletion, afaik

No the GC is not involved when using malloc and free.

Ah ok, thx for the large support! This one of the most tremendous things I love on your company, this and the technology you came up with :smiley: :smiley:

Keep going!

2 Likes

Yeah, SH, this time I agree with you :rofl:

2 Likes

haha at least one time :smiley:

There is always a first time :rofl:

2 Likes