PebbleOS v4.47.0-160-g9e782207f
Loading...
Searching...
No Matches
Scratch heap

Kernel heap for short-lived data. More...

Data Structures

struct  pbl_scratch_stats
 Usage of the scratch heap. More...
 

Functions

void * pbl_scratch_malloc (size_t size)
 Allocate from the scratch heap.
 
void * pbl_scratch_zalloc (size_t size)
 Allocate zeroed memory from the scratch heap.
 
void * pbl_scratch_zalloc_check (size_t size)
 Allocate zeroed memory from the scratch heap, asserting on failure.
 
void pbl_scratch_free (void *ptr)
 Free memory allocated from the scratch heap.
 
void pbl_scratch_get_stats (struct pbl_scratch_stats *stats)
 Get the usage of the scratch heap.
 

Detailed Description

Kernel heap for short-lived data.

A heap apart from the kernel's own (see Kernel heap), for buffers that only live for the length of an operation. Where it is and what it costs is the platform's business: it may be memory that is only powered while something is allocated, so what is allocated here should be freed as soon as it is no longer needed, and nothing should be kept for long.

uint8_t *buf = pbl_scratch_malloc(len);
if (buf == NULL) {
return -ENOMEM;
}
prv_process(buf, len);
void * pbl_scratch_malloc(size_t size)
Allocate from the scratch heap.
void pbl_scratch_free(void *ptr)
Free memory allocated from the scratch heap.

Data Structure Documentation

◆ pbl_scratch_stats

struct pbl_scratch_stats

Usage of the scratch heap.

Data Fields
unsigned int allocations Live allocations, 0 if not tracked.
size_t max_free Largest block that can be allocated now.
size_t peak Most bytes ever allocated at once, 0 if not tracked.
size_t size Size of the heap, in bytes.
size_t used Bytes allocated.

Function Documentation

◆ pbl_scratch_free()

void pbl_scratch_free ( void *  ptr)

Free memory allocated from the scratch heap.

Parameters
ptrMemory, or NULL.

◆ pbl_scratch_get_stats()

void pbl_scratch_get_stats ( struct pbl_scratch_stats *  stats)

Get the usage of the scratch heap.

Parameters
[out]statsUsage.

◆ pbl_scratch_malloc()

void * pbl_scratch_malloc ( size_t  size)

Allocate from the scratch heap.

The memory is aligned for any type. Not callable from interrupts.

Parameters
sizeSize, in bytes.
Returns
The memory, or NULL if there is no room.

◆ pbl_scratch_zalloc()

void * pbl_scratch_zalloc ( size_t  size)

Allocate zeroed memory from the scratch heap.

Parameters
sizeSize, in bytes.
Returns
The memory, or NULL if there is no room.

◆ pbl_scratch_zalloc_check()

void * pbl_scratch_zalloc_check ( size_t  size)

Allocate zeroed memory from the scratch heap, asserting on failure.

Parameters
sizeSize, in bytes.
Returns
The memory.