smalloc 1.0 review
Downloadsmalloc short from Static memory buffer malloc, is an ideal memory manager for Realtime Linux Kernel modules that can't use dynamic m
|
|
smalloc short from Static memory buffer malloc, is an ideal memory manager for Realtime Linux Kernel modules that can't use dynamic memory offered by kmalloc because of the non-realtime nature of kmalloc.
Like malloc(), smalloc() doles out memory to client code. Unlike malloc, however, smalloc takes a static memory buffer (as an initialization parameter). It is this buffer that smalloc manages when doling out memory to client code.
This design makes smalloc ideal for use inside a Realtime Linux kernel module. It also makes it much easire to port userspace code that relies on malloc() in C or operator new() in C++ for memory management to a realtime kernel module.
For example:
(the below is linux kernel code)
< code >
#include "smalloc.h"
#include < linux/slab.h >
#define MEMPOOLSZ (1024*1024*1024)
char *buf;
...
buf = kmalloc(MEMPOOLSZ, GFP_KERNEL); /* 1 megabyte buffer in kernel
module.. */
smalloc_set_memory_pool(buf, sizeof(buf));
...
MyStruct *s;
s = smalloc(sizeof(MyStruct)); /* example of code that uses this
static memory buffer */
< /code >
The above example is a typical usage pattern of smalloc.
smalloc 1.0 keywords