File: PsychMemory.h

package info (click to toggle)
psychtoolbox-3 3.0.14.20170103%2Bgit6-g605ff5c.dfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 103,044 kB
  • ctags: 69,483
  • sloc: ansic: 167,371; cpp: 11,232; objc: 4,708; sh: 1,875; python: 383; php: 344; makefile: 207; java: 113
file content (77 lines) | stat: -rwxr-xr-x 1,973 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
  Psychtoolbox2/Source/Common/PsychMemory.h		
  
  AUTHORS:
  Allen.Ingling@nyu.edu				awi
  mario.kleiner@tuebingen.mpg.de	mk

  PLATFORMS: All 
  
  PROJECTS: All

  HISTORY:
  09/04/02  awi		Wrote it.
  05/10/06  mk      Added our own allocator for Octave-Port.
  03/19/11  mk      Make 64-bit clean.  

  DESCRIPTION:

  TO DO: 

*/

//begin include once 
#ifndef PSYCH_IS_INCLUDED_PsychMemory
#define PSYCH_IS_INCLUDED_PsychMemory

// Convert a double value (which encodes a memory address) into a ptr:
void*  PsychDoubleToPtr(volatile double dptr);

// Convert a memory address pointer into a double value:
double PsychPtrToDouble(void* ptr);

//allocate memory which is valid between until control returns to
//the calling module
void *PsychCallocTemp(size_t n, size_t size);
void *PsychMallocTemp(size_t n);

//free memory
#if PSYCH_LANGUAGE == PSYCH_MATLAB
	#define PsychFreeTemp 			mxFree
#else

// Our own allocator / memory manager is used.

// PsychFreeTemp frees memory allocated with PsychM(C)allocTemp().
// This is not strictly needed as our memory manager will free
// the memory anyway when returning control to Matlab/Octave et al.
void PsychFreeTemp(void* ptr);

// Master cleanup routine: Frees all allocated memory.
void PsychFreeAllTempMemory(void);

// Pointer to the start of our list of allocated temporary memory buffers:
static size_t* PsychTempMemHead = NULL;
// Total count of allocated memory in Bytes:
static size_t totalTempMemAllocated = 0;

#endif

//allocate memory which is valid while the module is loaded

/*
	For Matlab this should 
	1- allocate memory with mxCalloc or mxMalloc
	2- call mexMakeMemoryPersistent on the pointer
	3- store the pointer in a linked list of pointers 
	   to memory which should be freed with MexAtExit
	   when the module is purged
	   
	do something similar on cleanup for environments where we use
	genuine malloc and calloc and free instead of the matlab 
	versions.
*/


//end include once
#endif