123456789101112131415161718192021222324252627282930313233343536373839 |
- #include <stdlib.h>
- #include <string.h>
- #include <stdio.h>
- #include "DataStorage.h"
- DataStorage::DataStorage()
- {
- bytes = (char *)calloc(4096,1);
- capacity = 4096;
- length = 0;
- }
- DataStorage::DataStorage(size_t size)
- {
- capacity = 4096;
- while(capacity < size) {
- capacity += 4096;
- }
- bytes = (char *)calloc(capacity,1);
- length = size;
- }
- DataStorage::~DataStorage()
- {
- free(bytes);
- }
- void DataStorage::appendBytes(const void *ptr, size_t size)
- {
- if(capacity < length + size) {
- do {
- capacity += 4096;
- } while(capacity < length + size);
- bytes = (char *)realloc(bytes, capacity);
- }
- memcpy(bytes+length, ptr, size);
- length += size;
- }
|