Re: Voting for FastCode rules on memory reading
- From: "Avatar Zondertau" <avatarzt@xxxxxxxxx>
- Date: 11 May 2005 09:43:10 -0700
> The rule about reading past the end of AnsiStrings were accepted
> because the MM allocated memory for strings up to (but not including)
> the first 4 byte aligned byte after the end of string (including #0
> terminator). We were sure that it was 100% safe to read the entire
> memory allocated for a string.
That depends on the memory manager. The Delphi help only specifies this
behavior only for the default memory manager (topic: Memory
Management). In general it isn't clear from the help file that this is
demanded of a memory manager (topic: TMemoryManager type; this topic is
clearly meant to specify how MM functions should behave in general, and
it does not mention alignment).
The reason that it is safe to read the entire last block is not the
specification of the MM, but the CPU protection mechanism: since an
aligned 32-bit block of data is always in only one page it is entriely
readable if one byte of it is.
AFAICS it would be theoretically both possible and legal to make a MM
that aligns all data on multiples of 7 for example. This could mean
that the last DWORD of the string is also used for something else. It
is still safe however, because the entire DWORD is in the same page.
.
- References:
- Voting for FastCode rules on memory reading
- From: Avatar Zondertau
- Re: Voting for FastCode rules on memory reading
- From: Dennis
- Re: Voting for FastCode rules on memory reading
- From: Avatar Zondertau
- Re: Voting for FastCode rules on memory reading
- From: Dennis
- Re: Voting for FastCode rules on memory reading
- From: Avatar Zondertau
- Re: Voting for FastCode rules on memory reading
- From: Aleksandr Sharahov
- Re: Voting for FastCode rules on memory reading
- From: Avatar Zondertau
- Re: Voting for FastCode rules on memory reading
- From: Aleksandr Sharahov
- Re: Voting for FastCode rules on memory reading
- From: Avatar Zondertau
- Re: Voting for FastCode rules on memory reading
- From: Aleksandr Sharahov
- Re: Voting for FastCode rules on memory reading
- From: Dennis
- Voting for FastCode rules on memory reading
- Prev by Date: Re: Voting for FastCode rules on memory reading
- Next by Date: Re: Voting for FastCode rules on memory reading
- Previous by thread: Re: Voting for FastCode rules on memory reading
- Next by thread: Re: Voting for FastCode rules on memory reading
- Index(es):
Relevant Pages
|