On Friday, 13 January 2023 at 14:57:40 UTC, Ali Çehreli wrote:
On 1/13/23 06:49, Gavin Ray wrote:

> I am curious if you can return something like
`ubyte[PAGE_SIZE]*` or
> `ref ubyte[PAGE_SIZE]`?

A simple cast seems to work:

enum PAGE_SIZE = 4096;
enum BUF_POOL_NUM_PAGES = 1024;
alias frame_idx_t = size_t;

ubyte[10_000] data;

ubyte[PAGE_SIZE]* get_page(frame_idx_t frame_idx)
{
    auto ptr = data.ptr + frame_idx * PAGE_SIZE;
    return cast(ubyte[PAGE_SIZE]*)ptr;
}

void main() {
}

Ali

Ah, much thanks Ali!

This is "valid" D I hope?

I searched Github for `"ubyte[4096]*"` and I found two uses of it, in the `xtrix` repo which seems to be an Operating System written in D:

![screenshot-of-ubyte-sized-ptr-on-github](https://i.imgur.com/WaAklbq.png)

Reply via email to