Is it possible to change the allocation area of automatic variables in C/C++? -
this theoretical question both c , c++.
i have 4x4 matrix type defined quite as:
typedef float matrix44[16];
i have many methods take matrix44
parameter, example:
bool matrixisidentity(matrix44 m);
i have custom memory allocation scheme in place whereby big area of memory pre-allocated on heap , manage allocations on prefetched memory manually. such have replaced/overloaded malloc
/new
own implementations. problem is, both custom malloc
, new
, nature, homecoming pointer, not object.
ordinarily, following:
// method 1 1] matrix44 mat = { ... }; 2] bool res = matrixisidentity(mat);
however, line 1 allocated mat
on stack, not in custom memory area wish. alternative is:
// method 2 1] matrix44 *mmat = mymalloc(...); 1a] matrix44 *nmat = new ... 2] bool res = matrixisidentity(*mat);
the issue here have litter code dereference operators. 1 alternative rewrite methods take matrix44*
instead, but, theoretical, assume not option.
therefore question becomes: there way declare automatic variable in c and/or c++ in method 1 line 1
, have follow alternate allocation scheme (as in method 2 line 1
)?
(i appreciate may involve compiler-related give-and-take have not added tags effect)
it not possible, automatic variables stack based. can whatever want within constructor. matrix44 lean wrapper around, say, matrix44impl point "custom" memory.
c++ c memory-management stack local-variables
No comments:
Post a Comment