Re: Optimizing Static Variable Layout
- From: randyhyde@xxxxxxxxxxxxx
- Date: 27 Apr 2005 08:14:45 -0700
Betov wrote:
> "f0dder" <spamtrap@xxxxxxxxxx> écrivait news:426ec27d$0$163
> $edfadb0f@xxxxxxxxxxxxxxxxxxxx:
>
> > Considering the kind of data used in most applications, I don't
> > think the savings you can achieve will justify the complexity
> > of implementing this feature - and it might come as a surprise
> > to people expecting their variable declarations to be linear in
> > memory.
>
> Not at all. This is a feature that is implemented
> in RosAsm since day one, and this is no problem at
> all, if correctly implemented, that is on a Block
> Base, and under full control of the Programmer.
It *does* come as a surprise to people who want to control the
placement of variables in RosAsm. If someone types:
[a:B$ 1]
[b:B$ 2]
They probably wouldn't expect these two declarations to consume eight
bytes in their static data's address space. Forcing the user to specify
byte alignment on byte declarations is hardly intuitive; as such,
f0dder is right - it just might come as a surprise.
As for the first issue f0dder raises, the complexity of the algorithm,
what RosAsm is doing is *not* what RosAsm is doing. RosAsm simply
injects extra bytes between each declaration block to force the
alignment to be dword-aligned. The proposal I'm making is to rearrange
the declarations in memory so that the extra padding bytes (needed for
values the programmer *explicitly* requests alignment for) might be
used for actual variables. For example, consider the following
declaration sections:
static(2)
w:word;
static(4)
d:dword;
static
b:byte;
c:byte;
If the assembler simply processed these declarations in the order it
encountered them, you'd probably expect the following memory layout:
0: w
2: two bytes of padding for alignment
4: d
8: b
9: c
However, as the declaration sections (beginning with "static" are all
independent (as the HLA documentation claims, for example), there is no
reason the assembler couldn't rearrange these declarations thusly:
0: w
2: b
3: c
4: d
Thus saving two bytes. That's what this "idea" is all about. Trying to
reusing those "padding" bytes wherever possible to hold actual data.
However, as f0dder correctly points out, this must be done *carefully*
because you don't want to violate intuition. Injecting extra padding
bytes, when they are not explicitly requested, is such a violation.
Cheers,
Randy Hyde
.
- Follow-Ups:
- Re: Optimizing Static Variable Layout
- From: Betov
- Re: Optimizing Static Variable Layout
- From: randyhyde
- Re: Optimizing Static Variable Layout
- Prev by Date: RosAsm injects extra bytes into your data
- Next by Date: RosAsm Team is Still Making Excuses
- Previous by thread: HAY BETOV, your apologies are overdue !
- Next by thread: Re: Optimizing Static Variable Layout
- Index(es):
Relevant Pages
|