mirror of
https://gitee.com/apaki/unicstl.git
synced 2026-05-28 22:54:19 +08:00
44 lines
1.1 KiB
C
44 lines
1.1 KiB
C
/**
|
|
* @file rawbuf.c
|
|
* @author wenjf (orig5826@163.com)
|
|
* @brief
|
|
* @version 0.1
|
|
* @date 2026-05-15
|
|
*
|
|
* @copyright Copyright (c) 2026
|
|
*
|
|
*/
|
|
#ifndef _RAWBUF_H_
|
|
#define _RAWBUF_H_
|
|
|
|
#include "unicstl_internal.h"
|
|
|
|
struct _rawbuf
|
|
{
|
|
// -------------------- private --------------------
|
|
void *obj;
|
|
size_t _obj_size;
|
|
size_t _capacity;
|
|
bool _dynamic;
|
|
|
|
void (*_destory)(struct _rawbuf *self);
|
|
// -------------------- public --------------------
|
|
// kernel -> random access
|
|
bool (*set)(struct _rawbuf *self, size_t index, const void *obj); // O(1)
|
|
bool (*get)(struct _rawbuf *self, size_t index, void *obj); // O(1)
|
|
const void* (*at)(struct _rawbuf *self, size_t index); // O(1)
|
|
|
|
// base
|
|
size_t (*capacity)(struct _rawbuf *self);
|
|
};
|
|
typedef struct _rawbuf *rawbuf_t;
|
|
|
|
rawbuf_t rawbuf_new(size_t obj_size, size_t capacity);
|
|
void rawbuf_free(rawbuf_t *rawbuf);
|
|
|
|
#ifdef UNICSTL_STATIC_MEMORY
|
|
bool rawbuf_init(struct _rawbuf *self, size_t obj_size, size_t capacity, void *mem_base);
|
|
#endif
|
|
|
|
#endif
|