Hi guys,
inside a wndproc, i am processing the WM_MOUSEMOVE
message, and inside that message i want to create a
RECT and POINT structs, like this:
but, if i have it correct, MASM will reorganise that code and
compile it in such a way that it comes out the same as if i had
written it this way:
Am i correct with this? If i am correct, what is the best way to
create those structs ONLY when processing the WM_MOUSEMOVE
message? (*without* branching to a subroutine). It just seems
wasteful to create them every time i enter the wndproc, when
they are only used for one message.
inside a wndproc, i am processing the WM_MOUSEMOVE
message, and inside that message i want to create a
RECT and POINT structs, like this:
[size=12]
WndProc proc uses edi hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
.IF uMsg == WM_MOUSEMOVE
[color=red]
LOCAL pt :POINT
LOCAL rect :RECT
[/color]
...code...
...code...
...etc....[/size]
but, if i have it correct, MASM will reorganise that code and
compile it in such a way that it comes out the same as if i had
written it this way:
[size=12]
WndProc proc uses edi hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
[color=red]
LOCAL pt :POINT
LOCAL rect :RECT
[/color]
.IF uMsg == WM_MOUSEMOVE
...code...
...code...
...etc....
[/size]
Am i correct with this? If i am correct, what is the best way to
create those structs ONLY when processing the WM_MOUSEMOVE
message? (*without* branching to a subroutine). It just seems
wasteful to create them every time i enter the wndproc, when
they are only used for one message.
I just compiled a little test app and masm wouldn't accept any locals if they where after code. To do what you want I think you would have to manually adjust the stack yourself.
I tried that once. MASM only likes the LOCAL directive after a PROC directive.
Sluggy Your are trying to allocate the locals at runtime. It can't be automatically done with compiled code.
Actually I just remembered a post by the svin he daid you could use the proc directive to make variables localised
Actually I just remembered a post by the svin he daid you could use the proc directive to make variables localised
sluggy, there isn't any problem in allocating the locals "all the time",
the only difference will be the amount subtracted from esp at the
procedure entry. Well, ok, if you were doing a lot of *huge* locals
this way there could theoretically be a problem because of the way
the stack grows (guard pages), but for stuff this small, don't worry :).
the only difference will be the amount subtracted from esp at the
procedure entry. Well, ok, if you were doing a lot of *huge* locals
this way there could theoretically be a problem because of the way
the stack grows (guard pages), but for stuff this small, don't worry :).
First of all, MASM assembles, it does not compile. :D
As to many locals, I agree with f0dder. I once wrote a very sloppy recursive directory lister which used about half a kilobyte of stack for local variables, and it would cause a stack underflow. Very inefficient. The rewritten version ended up using only 4 bytes for a local variable. :P
As to many locals, I agree with f0dder. I once wrote a very sloppy recursive directory lister which used about half a kilobyte of stack for local variables, and it would cause a stack underflow. Very inefficient. The rewritten version ended up using only 4 bytes for a local variable. :P
Why not just call a proc when the message is received?
For any message that does much work a write that into a proc, it also helps keeping WndProc from being so huge
gorshing
For any message that does much work a write that into a proc, it also helps keeping WndProc from being so huge
gorshing
f0dder & comrade,
i guess i was just looking for an unnecessary optimisation. I was actually in the middle of transcribing some C code, and of course you can do that in C.
gorshing,
of course, that is an option, but i figured that a jump to a sub would negate any benefit i gained through not declaring the vars at the start. If i was declaring heaps of vars for a message that occurred often, i would definately put it in a sub. But like i said above, i was just trying to be needlessly tight with my code :)
i guess i was just looking for an unnecessary optimisation. I was actually in the middle of transcribing some C code, and of course you can do that in C.
gorshing,
of course, that is an option, but i figured that a jump to a sub would negate any benefit i gained through not declaring the vars at the start. If i was declaring heaps of vars for a message that occurred often, i would definately put it in a sub. But like i said above, i was just trying to be needlessly tight with my code :)