The analogue of "fill-pointer" in D

Dennis Ritchie via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon May 18 03:24:22 PDT 2015


On Monday, 18 May 2015 at 10:14:33 UTC, Kagamin wrote:
> On Monday, 18 May 2015 at 08:21:38 UTC, Dennis Ritchie wrote:
>> Hi,
>>
>> In Common Lisp, there is such a thing as a fill-pointer 
>> (Example 5):
>> http://www.tutorialspoint.com/lisp/lisp_arrays.htm
>>
>> Does D some equivalent?
>
> Data stored in the array is indicated by the array length 
> property, use capacity to figure out extra available space: 
> http://dlang.org/phobos/object.html#.capacity

No, afraid not. Function capacity is not an analogue of 
fill-pointers!

Lisp-programmer explains the usefulness of fill-pointers as 
follows:

"Fill pointer "cuts" the tail of the vector. For example, vector 
elements 100, but if you set the fill pointer equal to 3, the 
length of the array (returned by length) will be equal to 3. The 
remaining elements are not visible.

It seems to be nonsense. But this is nonsense, ideal for buffers. 
If the buffer is implemented as an array, then fill pointer just 
marks the boundary of the filled part of the buffer, and adding a 
buffer (moving away from the fill pointer-a) is carried out using 
the vector-push. Or a buffer can be filled with the format-a. If 
you work with the same buffer C, fill pointer simulates a pointer 
to the last completed item."


More information about the Digitalmars-d-learn mailing list