That means you did write data into memory that you had already freed.
Or sometimes into memory you never had. I.e. into the internal data of the mem-manager.
You helped me finish a lock free producer / consumer ring buffer] implementation I needed ! ( at least after a lot of tests, I think it is lock free .... :) )Well you don't call any "locks", "critical sections" or similar. So it's lock free.
Since you say "lock free", I assume there are multiple threads using this?
Is that ONE, and no more than just ONE thread for writing?
And
Is that ONE, and no more than just ONE thread for reading?
Example: MemSize = 1024; ; WriteIndex = 1020; ReadIndex = 1021
function TRingBuffer.GetCapacity: PtrUInt; inline; var r, w: PtrUInt; begin r := FReadIndex; w := FWriteIndex; {$PUSH}{$R-}{$Q-} result := (w - r) and and (FMemorySize - 1); // it seems from MaskIndex, that memsize is a 2^n value. {$POP} end;
w - r = -1 // -1 in unsigned $ffffffffff // $ffffffffff and 1023 = 1023
And indeed 1023 bytes are in use.
(Not sure if GetCapacity needs a ReadBarrier)
Using "Interlocked...." commands (if they translate directly into asm, like they do on intel/amd), is really a lot simpler.
Using "Interlocked...." commands (if they translate directly into asm, like they do on intel/amd), is really a lot simpler.
I'm going to use this code in AVR mcu also, thats why I tried to avoid to use the Interlockedxxxxxx "family". Maybe I'm wrong, need to think about it .