Array struct

This commit is contained in:
2022-10-28 11:57:18 +06:00
parent f8a610ace0
commit e2ecfc3d27
4 changed files with 111 additions and 0 deletions

40
src/Array/Array_declare.h Normal file
View File

@@ -0,0 +1,40 @@
#pragma once
#if __cplusplus
extern "C" {
#endif
#include "../base/base.h"
#define Array_declare(type)\
typedef struct Array_##type{\
type* values;\
uint32 length;\
bool allocatedOnHeap;\
} Array_##type;\
\
\
static inline Array_##type Array_##type##_allocValues(uint32 length){\
return (Array_##type) {\
.values=malloc(sizeof(type)*length),\
.length=length,\
.allocatedOnHeap=true\
};\
}\
\
static inline Array_##type Array_##type##_fromBuffer(buffer, bufferLength, allocatedOnHeap){\
return (Array_##type) {\
.values=buffer,\
.length=bufferLength,\
.allocatedOnHeap=allocatedOnHeap\
};\
}\
\
static inline void Array_##type##_freeValues(Array_##type* array){\
if(array->allocatedOnHeap)\
free(array->values);\
}
#if __cplusplus
}
#endif