---
name: "rbucket"
section: "3"
platform: "linux"
package: "libroy-dev"
version: "1.0.8-1"
release: "Debian 3.1 (Sarge)"
platforms: ["linux"]
url: "https://new.carta.tech/rbucket"
---

# rbucket(3)

Roy bucket memory allocator

## NAME

rbucket - Roy bucket memory allocator

## SYNOPSIS

\#include \<roy.h\>

RBucket \* rbucket\_new (unsigned int size);

void rbucket\_empty (RBucket \*bucket);

void rbucket\_destroy (RBucket \*bucket);

void \* rbucket\_alloc (RBucket \*bucket);

void rbucket\_free (RBucket \*bucket, void \*mem);

## DESCRIPTION

RBucket implements an even faster memory allocator than [*rchunk*(3)](/rchunk/3.md). This one uses a structure *RBucket* to contain the pool of memory from which it allocates and frees.  Unlike [*rchunk*(3)](/rchunk/3.md), rbucket does not perform any thread locking, and only allocates chunks of sizes as specified by *rbucket\_new*(3).

As rbucket does not perform thread locking, it is generally expected that rbucket will be used per-thread, or the user will have to do the locking. See [*rthread*(3)](/rthread/3.md) for details on roy threading, and [*rthread\_mutex*(3)](/rthread_mutex/3.md) for mutexes in particular.

The speed achieved by rbucket is almost that of using [*alloca*(3)](/alloca/3.md), but is safe for use on all platforms.

*rbucket\_new*(3) creates a new bucket that will allow you to allocate *size* sized blocks of memory from it.

*rbucket\_destroy*(3) frees the RBucket structure and ALL memory used in ALL blocks allocated from this bucket.  Blocks allocated with *rbucket\_alloc*(3) are freed along with those still in the bucket. Again, ALL memory used by the bucket is freed, whether allocated or not.

*rbucket\_empty*(3) frees all blocks in *bucket*, both those in use and not in use, but does not destroy the RBucket structure itself so that it can continue to be used.

*rbucket\_alloc*(3) allocates a block from *bucket*.  This returns a newly allocated block of memory of the size specified in *rbucket\_new*(3).

*rbucket\_alloc0*(3) allocates a block from *bucket* the same as *rbucket\_alloc*(3), but zeros the memory before returning it.

*rbucket\_free*(3) returns the block of memory *mem* back to the  *bucket*.  It will then be made available for future allocations with *rbucket\_alloc*(3).

## MACROS

rbucket\_alloc, rbucket\_alloc0, and rbucket\_free are implemented as macros, though there should never be a problem with their behavior if used as functions.

## SEE ALSO

[*roy*(3)](/roy/3.md)
