-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathnrt_external.h
More file actions
65 lines (45 loc) · 1.82 KB
/
nrt_external.h
File metadata and controls
65 lines (45 loc) · 1.82 KB
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
#ifndef NUMBA_NRT_EXTERNAL_H_
#define NUMBA_NRT_EXTERNAL_H_
#include <stdlib.h>
typedef struct MemInfo NRT_MemInfo;
typedef void NRT_managed_dtor(void *data);
typedef void *(*NRT_external_malloc_func)(size_t size, void *opaque_data);
typedef void *(*NRT_external_realloc_func)(void *ptr, size_t new_size, void *opaque_data);
typedef void (*NRT_external_free_func)(void *ptr, void *opaque_data);
struct ExternalMemAllocator {
NRT_external_malloc_func malloc;
NRT_external_realloc_func realloc;
NRT_external_free_func free;
void *opaque_data;
};
typedef struct ExternalMemAllocator NRT_ExternalAllocator;
typedef struct {
/* Methods to create MemInfos.
MemInfos are like smart pointers for objects that are managed by the Numba.
*/
/* Allocate memory
*nbytes* is the number of bytes to be allocated
Returning a new reference.
*/
NRT_MemInfo* (*allocate)(size_t nbytes);
/* Allocates memory using an external allocator but still using Numba's MemInfo.
*
* NOTE: An externally provided allocator must behave the same way as C99
* stdlib.h's "malloc" function with respect to return value
* (including the behaviour that occurs when requesting an allocation
* of size 0 bytes).
*/
NRT_MemInfo* (*allocate_external)(size_t nbytes, NRT_ExternalAllocator *allocator);
/* Convert externally allocated memory into a MemInfo.
*data* is the memory pointer
*dtor* is the deallocator of the memory
*/
NRT_MemInfo* (*manage_memory)(void *data, NRT_managed_dtor dtor);
/* Acquire a reference */
void (*acquire)(NRT_MemInfo* mi);
/* Release a reference */
void (*release)(NRT_MemInfo* mi);
/* Get MemInfo data pointer */
void* (*get_data)(NRT_MemInfo* mi);
} NRT_api_functions;
#endif /* NUMBA_NRT_EXTERNAL_H_ */