1234567891011121314151617181920212223242526272829 |
- #include "core/Buffer.h"
- #include <string.h>
- #include "core/Utility.h"
- void initBuffer(Buffer* b) {
- b->buffer = nullptr;
- b->capacity = 0;
- b->size = 0;
- }
- void destroyBuffer(Buffer* b) {
- coreFree(b->buffer);
- initBuffer(b);
- }
- void addSizedBufferData(Buffer* b, const void* data, size_t size) {
- while(b->size + size >= b->capacity) {
- b->capacity = b->capacity == 0 ? 8 : (b->capacity * 5) / 4;
- b->buffer = coreReallocate(b->buffer, b->capacity);
- }
- memcpy(b->buffer + b->size, data, size);
- b->size += size;
- }
- void clearBuffer(Buffer* b) {
- b->size = 0;
- }
|