Creating a pointer/slice to a specific-size buffer? (Handing out a page/frame from a memory manager)

H. S. Teoh hsteoh at qfbox.info
Fri Jan 13 19:16:17 UTC 2023


On Fri, Jan 13, 2023 at 08:31:17AM -0800, Ali Çehreli via Digitalmars-d-learn wrote:
> On 1/13/23 07:07, Gavin Ray wrote:
> 
> > This is "valid" D I hope?
> 
> Yes because static arrays are just elements side-by-side in memory.
> You can cast any piece of memory to a static array provided the length
> and alignment are correct.
[...]

Or to be more precise, cast the memory to a *pointer* to a static array
of the right size.  Static arrays are by-value types; passing around the
raw array will cause the array to be copied every time, which is
probably not what is intended.


T

-- 
"You are a very disagreeable person." "NO."


More information about the Digitalmars-d-learn mailing list