Skip to content

Commit

Permalink
Update docs for new gc array interface.
Browse files Browse the repository at this point in the history
  • Loading branch information
schveiguy committed Jan 3, 2025
1 parent 45e4a09 commit 02a9116
Showing 1 changed file with 38 additions and 27 deletions.
65 changes: 38 additions & 27 deletions druntime/src/core/gc/gcinterface.d
Original file line number Diff line number Diff line change
Expand Up @@ -193,28 +193,33 @@ interface GC

// ARRAY FUNCTIONS
/**
* Get the current used capacity of an array block. Note that this is only
* needed if you are about to change the array used size and need to deal
* with the memory that is about to go away. For appending or shrinking
* arrays that have no destructors, you probably don't need this function.
* Get the current used capacity of an array block.
*
* Note that this is only needed if you are about to change the array used
* size and need to deal with the memory that is about to go away. For
* appending or shrinking arrays that have no destructors, you probably
* don't need this function.
*
* Params:
* ptr = The pointer to check. This can be an interior pointer, but if it
* is beyond the end of the used space, the return value may not be
* valid.
* atomic = If true, the value is fetched atomically (for shared arrays)
* Returns: Current array slice, or null if the pointer does not point to a
* valid appendable GC block.
* atomic = The value is fetched atomically (for shared arrays)
* Returns:
* Current array slice, or null if the pointer does not point to a valid
* appendable GC block.
*/
void[] getArrayUsed(void *ptr, bool atomic = false) nothrow;

/**
* Expand the array used size. Used for appending and expanding the length
* of the array slice. If the operation can be performed without
* reallocating, the function succeeds. Newly expanded data is not
* initialized.
* Expand the array used size in place.
*
* Used for appending and expanding the length of the array slice. If the
* operation can be performed without reallocating, the function succeeds.
* Newly expanded data is not initialized. Slices that do not point at
* expandable GC blocks cannot be affected, and this function will always
* return false.
*
* slices that do not point at expandable GC blocks cannot be affected, and
* this function will always return false.
* Params:
* slice = the slice to attempt expanding in place.
* newUsed = the size that should be stored as used.
Expand All @@ -225,37 +230,43 @@ interface GC
bool expandArrayUsed(void[] slice, size_t newUsed, bool atomic = false) nothrow @safe;

/**
* Expand the array capacity. Used for reserving space that can be used for
* appending. If the operation can be performed without reallocating, the
* function succeeds. The used size is not changed.
* Expand the array capacity in place.
*
* Used for reserving space that can be used for appending. If the
* operation can be performed without reallocating, the function succeeds.
* The used size is not changed. Slices that do not point at expandable GC
* blocks cannot be affected, and this function will always return zero.
*
* slices that do not point at expandable GC blocks cannot be affected, and
* this function will always return zero.
* Params:
* slice = the slice to attempt reserving capacity for.
* request = the requested size to expand to. Includes the existing data.
* Passing a value less than the current array size will result in no
* changes, but will return the current capacity.
* atomic = if true, the array may be shared between threads, and this
* operation should be done atomically.
* Returns: resulting capacity size, 0 if the operation could not be performed.
* atomic = The array may be shared between threads, and this operation
* should be done atomically.
*
* Returns:
* Resulting capacity size or 0 if the operation could not be performed.
*/
size_t reserveArrayCapacity(void[] slice, size_t request, bool atomic = false) nothrow @safe;

/**
* Shrink used space of a slice. Unlike the other array functions, the
* array slice passed in is the target slice, and the existing used space
* is passed separately. This is to discourage code that ends up with a
* slice to dangling valid data.
* Shrink used space of a slice in place.
*
* Unlike the other array functions, the array slice passed in is the
* target slice, and the existing used space is passed separately. This is
* to discourage code that ends up with a slice to dangling valid data.
*
* If slice.ptr[0 .. existingUsed] does not point to the end of a valid GC
* appendable slice, then the operation fails.
*
* Params:
* slice = The proposed valid slice data.
* existingUsed = The amount of data in the block (starting at slice.ptr)
* that is currently valid in the array. If this amount does not match
* the current used size, the operation fails.
* atomic = If true, the slice may be shared between threads, and the
* operation should be atomic.
* atomic = The slice may be shared between threads, and the operation
* should be atomic.
* Returns: true if successful.
*/
bool shrinkArrayUsed(void[] slice, size_t existingUsed, bool atomic = false) nothrow;
Expand Down

0 comments on commit 02a9116

Please sign in to comment.