Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
OBITools3
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
23
Issues
23
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
Operations
Operations
Incidents
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
OBITools
OBITools3
Commits
3aec0d7b
Commit
3aec0d7b
authored
May 23, 2015
by
Eric Coissac
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add function for estimating the size of an obitype or of an array of
obitype.
parent
57db677d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
87 additions
and
8 deletions
+87
-8
src/obitypes.c
src/obitypes.c
+53
-0
src/obitypes.h
src/obitypes.h
+34
-8
No files found.
src/obitypes.c
0 → 100644
View file @
3aec0d7b
/*
* 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
;
}
src/obitypes.h
View file @
3aec0d7b
/****************************************************************************
* OBITypes header file *
****************************************************************************/
/**
* @file obitypes.h
* @author Celine Mercier
...
...
@@ -13,6 +9,7 @@
#define OBITYPES_H_
#include <stdio.h>
#include <unistd.h>
#define OBIInt_NA (INT32_MIN)
#define OBIFloat_NA (NAN)
...
...
@@ -35,10 +32,10 @@ typedef enum {
typedef
enum
OBIType
{
OBI_VOID
=
0
,
/**< data type not specified */
OBI
Int_t
,
/**< a signed integer value (C type : int32_t) */
OBI
Float_t
,
/**< a floating value (C type : double) */
OBI
Char_t
,
/**< a character (C type : char) */
OBI
Idx_t
/**< an index in a data structure (C type : size_t) */
OBI
_INT
,
/**< a signed integer value (C type : int32_t) */
OBI
_FLOAT
,
/**< a floating value (C type : double) */
OBI
_CHAR
,
/**< a character (C type : char) */
OBI
_IDX
/**< an index in a data structure (C type : size_t) */
}
OBIType_t
,
*
OBIType_p
;
typedef
int32_t
obiint_t
;
...
...
@@ -46,5 +43,34 @@ typedef double obifloat_t;
typedef
char
obichar_t
;
typedef
size_t
obiidx_t
;
/**
* @brief returns the memory size in bytes of an OBIType
*
* @param type the OBIType code used as query
*
* @return the size in bytes of the type
* @retval 0 on error (unknown type)
*
* @since May 2015
* @author Eric Coissac (eric.coissac@metabarcoding.org)
*/
size_t
obi_sizeof
(
OBIType_t
type
);
/**
* @brief returns the size requested to store an array of OBIType
*
* The returned size is enouth large to store an array of size nbelement
* but rounded at a multiple of the memory page size.
*
* @param type the OBIType code used as query
* @param nbelement the number of element to be stored
*
* @return the size in bytes of the type
* @retval 0 on error (unknown type)
*
* @since May 2015
* @author Eric Coissac (eric.coissac@metabarcoding.org)
*/
size_t
obi_array_sizeof
(
OBIType_t
type
,
size_t
nbelement
);
#endif
/* OBITYPES_H_ */
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment