flat assembler
Message board for the users of flat assembler.

Index > High Level Languages > stack locals or heap globals?

Author
Thread Post new topic Reply to topic
Defoc8



Joined: 01 Jul 2006
Posts: 2
Defoc8 12 Aug 2006, 05:54
hi..im new to all this 8086 coding lark...havent looked at assembler since
the amiga.. - anyway to the point. I was wondering whether in general it is faster
to access stack data than global/heap data?...

what about something like a matrix? - would i be better off reserving
stack space for matrices for potentially faster access or would i be better
off using temp matrix objects on the heap + simply uses the address in
functions/procedures?

sorry if the questions are stupid.. Sad

I ony have a very basic understanding of 8086 assembler and how windows
works internally..so any feedback would be greatly appreciated Wink

cheers!
matt.
Post 12 Aug 2006, 05:54
View user's profile Send private message Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3175
Location: Denmark
f0dder 12 Aug 2006, 10:51
There tends to be a bit better chance of the stack being in the CPU cache because, well, the stack is used all the time. On the other hand, the stack is somewhat limited in size, so you shouldn't allocate too large objects there (I tend to go heap once I need more than a few kilobytes).

Stack variables have the advantage of being easier to make thread-safe than use of global variables. But of course you can HeapAlloc and save pointers in stack variables.
Post 12 Aug 2006, 10:51
View user's profile Send private message Visit poster's website Reply with quote
Defoc8



Joined: 01 Jul 2006
Posts: 2
Defoc8 13 Aug 2006, 13:12
thanks - i dont know anything about the cache, last time i coded in assembler
there was no instruction or data cache..and no fpu/mmu :p
..will probably need to hunt out some docs on modern processor architecture..
its all very interesting, if a little confusing..i think i much prefered 68k assembler
Wink
Post 13 Aug 2006, 13:12
View user's profile Send private message Reply with quote
donkey7



Joined: 31 Jan 2005
Posts: 127
Location: Poland, Malopolska
donkey7 13 Aug 2006, 13:21
http://www.agner.org/optimize/ - here are many useful docs
Post 13 Aug 2006, 13:21
View user's profile Send private message Visit poster's website Reply with quote
0x4e71



Joined: 25 Feb 2004
Posts: 50
0x4e71 13 Aug 2006, 14:27
Also worth reading this presentation by Felix von Leitner, see the bit about alloca vs malloc/new.

http://www.fefe.de/dietlibc/diet.pdf

Quote:

i think i much prefered 68k assembler

Me too Smile
But then again x86's have advantages too, they come with GHz+ clock speeds at dirt cheap prices Wink
Post 13 Aug 2006, 14:27
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.