Is it possible to change the distribution area of ​​automatic variables in C / C ++?

This is a theoretical question for C and C ++.

I have a 4x4 matrix type that is defined simply like this:

typedef float   Matrix44[16];

I also have many methods that take Matrix44as a parameter, for example:

bool matrixIsIdentity(Matrix44 m);

I also have a special memory allocation scheme in which a large area of ​​memory is pre-allocated on the heap, and then I manually manage the allocations in this pre-loaded memory. So I replaced / overloaded malloc/ newwith my own implementations. The problem is that both user mallocand newby nature return a pointer, not an object.

Usually I just did the following:

   // Method 1
1] Matrix44 mat = { ... };
2] bool res = matrixIsIdentity(mat);

1 mat , , . :

    // Method 2
1]  Matrix44 *mmat = myMalloc(...);
1a] Matrix44 *nmat = new ...
2]  bool res = matrixIsIdentity(*mat);

, . Matrix44*, , , , .

: C / ++, Method 1 Line 1, ( Method 2 Line 1)?

( , , , )

+5
2

, . , . , Matrix44 , , Matrix44Impl, "" .

+4

, 100% , , , , , , :

Matrix44& mmat = *new Matrix44(...);   // or *myMalloc() or whatever

mmat.Rotate(45.0);
bool res = matrixIsIdentity(mat);
...
delete &mmat; // or myFree(&mmat) or something similar

new - delete, , , , , / . , "" .

. "" , . , , , . .

-, , , ( !) delete, , , , - , , "" ".

+2

All Articles