B
Brian Lindahl
I'm using a temporary buffer to transfer some data and would rather
not allocate it on the heap. The problem is that the size of the
buffer is only known upon entry into the function that utilizes it and
I'd rather not waste space or dynamically allocate on the heap (since
it doesn't need to persist). Now I'm planning on utilizing inline
assembly to modify the stack pointer directly to allocate the space I
need.
Here's an example:
void doSomeStuff(unsigned size) {
char* rawData;
//INLINED (Intel p4 assembly)
//sub esp, dword ptr [size]
//mov dword ptr [rawData], esp
//do some stuff with the temporary buffer, using rawData to access
it
//INLINED (Intel p4 assembly)
//add esp, dword ptr [size]
}
As far as I know, it should work just fine, like magic - no problems
at all. BUT, is this assumption correct? Are there any odd quirks that
I should be aware of that I may not have thought of?
not allocate it on the heap. The problem is that the size of the
buffer is only known upon entry into the function that utilizes it and
I'd rather not waste space or dynamically allocate on the heap (since
it doesn't need to persist). Now I'm planning on utilizing inline
assembly to modify the stack pointer directly to allocate the space I
need.
Here's an example:
void doSomeStuff(unsigned size) {
char* rawData;
//INLINED (Intel p4 assembly)
//sub esp, dword ptr [size]
//mov dword ptr [rawData], esp
//do some stuff with the temporary buffer, using rawData to access
it
//INLINED (Intel p4 assembly)
//add esp, dword ptr [size]
}
As far as I know, it should work just fine, like magic - no problems
at all. BUT, is this assumption correct? Are there any odd quirks that
I should be aware of that I may not have thought of?