Add function for estimating the size of an obitype or of an array of

obitype.
This commit is contained in:
2015-05-23 16:50:49 +03:00
parent 57db677d1f
commit 3aec0d7b50
2 changed files with 87 additions and 8 deletions

53
src/obitypes.c Normal file
View File

@ -0,0 +1,53 @@
/*
* obitypes.c
*
* Created on: 23 mai 2015
* Author: coissac
*/
#include <obitypes.h>
size_t obi_sizeof(OBIType_t type) {
size_t size=0
switch (type) {
case OBI_VOID: size = 1;
break;
case OBI_INT: size = sizeof(obiint_t);
break;
case OBI_FLOAT: size = sizeof(obifloat_t);
break;
case OBI_CHAR: size = sizeof(obichar_t);
break;
case OBI_IDX: size = sizeof(obiidx_t);
break;
default: size = 0;
}
return size;
}
size_t obi_array_sizeof(OBIType_t type,size_t nbelement) {
size_t size;
size_t rsize;
size_t psize;
size = obi_sizeof(type) * nbelement;
psize= getpagesize();
rsize= size % psize;
// Round at a size multiple of pagesize
if (rsize)
size = (size / psize) * psize + psize;
return size;
}