File: PsychMemory.h

package info (click to toggle)
psychtoolbox-3 3.0.19.14.dfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 86,796 kB
  • sloc: ansic: 176,245; cpp: 20,103; objc: 5,393; sh: 2,753; python: 1,397; php: 384; makefile: 193; java: 113
file content (69 lines) | stat: -rw-r--r-- 1,779 bytes parent folder | download | duplicates (4)
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
/*
  Psychtoolbox/Source/Common/PsychMemory.h

  AUTHORS:

  Allen.Ingling@nyu.edu             awi
  mario.kleiner.de@gmail.com        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.  

*/

//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* inptr);

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

#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