MCPcopy Create free account
hub / github.com/OGSR/OGSR-Engine / alloc

Method alloc

3rd_party/Src/ode/ode/src/obstack.cpp:62–92  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

60
61
62void *dObStack::alloc (int num_bytes)
63{
64 if ((size_t)num_bytes > MAX_ALLOC_SIZE) dDebug (0,"num_bytes too large");
65
66 // allocate or move to a new arena if necessary
67 if (!first) {
68 // allocate the first arena if necessary
69 first = last = (Arena *) dAlloc (dOBSTACK_ARENA_SIZE);
70 first->next = 0;
71 first->used = sizeof (Arena);
72 ROUND_UP_OFFSET_TO_EFFICIENT_SIZE (first,first->used);
73 }
74 else {
75 // we already have one or more arenas, see if a new arena must be used
76 if ((last->used + num_bytes) > dOBSTACK_ARENA_SIZE) {
77 if (!last->next) {
78 last->next = (Arena *) dAlloc (dOBSTACK_ARENA_SIZE);
79 last->next->next = 0;
80 }
81 last = last->next;
82 last->used = sizeof (Arena);
83 ROUND_UP_OFFSET_TO_EFFICIENT_SIZE (last,last->used);
84 }
85 }
86
87 // allocate an area in the arena
88 char *c = ((char*) last) + last->used;
89 last->used += num_bytes;
90 ROUND_UP_OFFSET_TO_EFFICIENT_SIZE (last,last->used);
91 return c;
92}
93
94
95void dObStack::freeAll()

Callers 1

createJointFunction · 0.45

Calls 2

dDebugFunction · 0.85
dAllocFunction · 0.85

Tested by

no test coverage detected