App hangs, GC.collect() fixet it. Why?
schveiguy at gmail.com
Mon Sep 28 15:44:44 UTC 2020
On 9/28/20 8:57 AM, Bastiaan Veelo wrote:
> I am glad to have found the cause of the breakage finally, but it won't
> be easy to find a generic solution...
Obviously, this isn't a real piece of code, but there is no way around
this. You have to align your pointers. The other option is to not use
the GC and use manual memory management.
If this is a compatibility thing between D and Pascal, and you
absolutely have to have the same layout, is there a way to adjust the
structure in Pascal? Like put the elements that misalign the pointers at
the end of the structure?
Another totally drastic approach would be to supply your own
even-more-conservative GC which will scan misaligned pointers. Probably
going to hurt performance quite a bit. You might be able to get away
with marking only certain blocks as having misaligned pointers, but you
will have to scan all the stacks with this assumption.
Some more information about the setup you are using might help (I'm
assuming D and Pascal are using the same memory in the same process,
otherwise this wouldn't be a problem). In particular, where does the
data come from, and how malleable is it in your system? Are there times
where references to the D data only exist in Pascal?
More information about the Digitalmars-d-learn