spBase
Loading...
Searching...
No Matches
spMemory.h
Go to the documentation of this file.
1
4#ifndef __SPMEMORY_H
5#define __SPMEMORY_H
6
7#include <sp/spDefs.h>
8
9#ifdef __cplusplus
10extern "C" {
11#endif
12
16 /*----@addtogroup spMemoryGroup----*/
17
18#ifdef MACOS
19#undef SP_USE_MAC_MEMORY
20#endif
21
22#if defined(MACOS)
23#pragma import on
24#endif
25
26extern void spSetMemoryErrorExit(int flag);
28extern char *xspMalloc(int nbytes);
30extern char *xspRemalloc(char *p, int nbytes);
32extern void _xspFree(char *p);
33
35extern int **xspIMatAlloc(int row, int col);
37extern void xspIMatFree(int **mat, int row);
39extern short **xspSMatAlloc(int row, int col);
41extern void xspSMatFree(short **mat, int row);
43extern long **xspLMatAlloc(int row, int col);
45extern void xspLMatFree(long **mat, int row);
47extern float **xspFMatAlloc(int row, int col);
49extern void xspFMatFree(float **mat, int row);
51extern double **xspDMatAlloc(int row, int col);
53extern void xspDMatFree(double **mat, int row);
54
56extern char **xspCMatAlloc(int row, int col);
58extern void xspCMatFree(char **mat, int row);
60extern unsigned char **xspUCMatAlloc(int row, int col);
62extern void xspUCMatFree(unsigned char **mat, int row);
63
65extern char *xspStrClone(const char *string);
66
67#if defined(MACOS)
68#pragma import off
69#endif
70
71#if defined(_WIN32) && defined(_DEBUG) && defined(_CRTDBG_MAP_ALLOC)
72#define xspAlloc(n, type) (type *)malloc((int)(n)*sizeof(type))
73#define xspRealloc(p, n, type) (type *)realloc((char *)(p), (int)(n)*sizeof(type))
74#define xspFree(p) {free((char *)(p)); (p) = NULL;}
75#define xspStrClone(p) _strdup(p)
76#else
78#define xspAlloc(n, type) (type *)xspMalloc((int)(n)*sizeof(type))
80#define xspRealloc(p, n, type) (type *)xspRemalloc((char *)(p), (int)(n)*sizeof(type))
82#define xspFree(p) {_xspFree((char *)(p)); (p) = NULL;}
83#endif
84
85#define spStrReplace(s1, s2) {if ((s1) != NULL) xspFree(s1); (s1) = (((s2) != NULL) ? xspStrClone(s2) : NULL);}
87#define spArrayCopy(p1, p2, n, type) memmove((char *)(p1), (char *)(p2), (unsigned)(n)*sizeof(type))
88
89#if !defined(SP_DISABLE_ABBREVIATION)
90#ifndef xalloc
91#define xalloc(n, type) xspAlloc(n, type)
92#endif
93#ifndef xrealloc
94#define xrealloc(p, n, type) xspRealloc(p, n, type)
95#endif
96#ifndef xfree
97#define xfree(p) xspFree(p)
98#endif
99
100#ifndef strclone
101#define strclone(string) xspStrClone(string)
102#endif
103#ifndef strrepl
104#define strrepl(s1, s2) spStrReplace(s1, s2)
105#endif
106#ifndef arrcpy
107#define arrcpy(p1, p2, n, type) spArrayCopy(p1, p2, n, type)
108#endif
109#endif /* !defined(SP_DISABLE_ABBREVIATION) */
110
111 /*----@addtogroup spMemoryGroup----*/
112
113#ifdef __cplusplus
114} /* Close scope of 'extern "C"' declaration */
115#endif
116
117#endif /* __SPMEMORY_H */
float ** xspFMatAlloc(int row, int col)
void xspUCMatFree(unsigned char **mat, int row)
void xspIMatFree(int **mat, int row)
char * xspStrClone(const char *string)
void _xspFree(char *p)
void xspCMatFree(char **mat, int row)
void xspDMatFree(double **mat, int row)
long ** xspLMatAlloc(int row, int col)
double ** xspDMatAlloc(int row, int col)
short ** xspSMatAlloc(int row, int col)
void xspLMatFree(long **mat, int row)
void xspSMatFree(short **mat, int row)
char * xspRemalloc(char *p, int nbytes)
unsigned char ** xspUCMatAlloc(int row, int col)
char * xspMalloc(int nbytes)
void xspFMatFree(float **mat, int row)
char ** xspCMatAlloc(int row, int col)
int ** xspIMatAlloc(int row, int col)