Hello guys

Hello guys,

How do I extract the pointer to the underlying array of a dynamic array?
Since a dynamic array is actually a field for the length and a pointer to the raw data, I am wondering how to use dynamic arrays to play with native C APIs that only accept plain array pointers. I am used to play with static arrays for this role, however this time I am unable to use it once the initial size of the array is unknown. I would love to appreciate your help, thanks in advance :D

Given I have:
var
Buffer: TArray;

Is it possible to extract PByte from that without having to perform copies?

Comments

  1. The array pointer points to the first item. The information about the length and the RecCount are at a negative offset (see System.TDynArrayRec)

    Keep in mind that you should only use this for external APIs that require preallocated memory/array (they usually also ask the size of the memory you are passing).

    ReplyDelete

Post a Comment