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

Ali Çehreli acehreli at yahoo.com
Fri Jan 13 16:37:55 UTC 2023


On 1/13/23 07:22, Gavin Ray wrote:
 > Maybe it would be better to wrap the slice in a new class with an
 > invariant?

Possibly but please check before using because I think 'invariant' 
requires presence of member functions:

   https://dlang.org/spec/struct.html#Invariant

 > Because what I want to do is:
 >
 > 1. Ensure that the length of the underlying referenced/pointed-to data
 > is `PAGE_SIZE`

My first thought was why not use a slice anyway?

Worth noting that static arrays are value types. Also, they all have 
different types from each other and have the potential to cause template 
bloat.

 > class BufferPool

Off-topic, most D programmers use struct unless they need class.

 >      Frame[BUF_POOL_NUM_PAGES] frames;

Makes sense to me.

Ali



More information about the Digitalmars-d-learn mailing list