 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Dennis Guest
|
Posted: Mon May 30, 2005 6:05 pm Post subject: New Rule Suggestion |
|
|
Hi All
I would like us to discuss a new rule.
"A function returning a string as result must allocate enough memory for
that string and not more"
I think that is a bad idead to allocate to much memory for strings and just
setting the Length variable short.
Any suggestions to improve the wording of the rule?
Any opinions before we start voting?
Best regards
Dennis
|
|
| Back to top |
|
 |
Anders Isaksson Guest
|
Posted: Tue May 31, 2005 6:22 am Post subject: Re: New Rule Suggestion |
|
|
On Mon, 30 May 2005 20:05:10 +0200, "Dennis"
<marianndkc (AT) home3 (DOT) gvdnet.dk> wrote:
| Quote: | I would like us to discuss a new rule.
"A function returning a string as result must allocate enough memory for
that string and not more"
|
Why? What's the point of this rule? Which problem does it remove?
If an algorithm can be made faster by allocating a bit more memory than
the final Result will need, what's the problem? Thats a valid solution
to boundary problems (sentinel values instead of repeatedly checking the
index, for example).
Or will the extra memory be orphaned? If so a validation would show
memory leaks, right?
--
Anders Isaksson, Sweden
BlockCAD: http://web.telia.com/~u16122508/proglego.htm
Gallery: http://web.telia.com/~u16122508/gallery/index.htm
|
|
| Back to top |
|
 |
Aleksandr Sharahov Guest
|
Posted: Tue May 31, 2005 6:43 am Post subject: Re: New Rule Suggestion |
|
|
Hi Dennis,
| Quote: | I would like us to discuss a new rule.
"A function returning a string as result must allocate enough memory
for
that string and not more"
I think that is a bad idead to allocate to much memory for strings and
just
setting the Length variable short.
|
Borland votes "No" (see NewAnsiString).
This function rounds size up to full word.
My new UpperCase & LowerCase functions
round size up to full dword.
Is there big differnce?
There is no difference, because all existing MMs
allocate memory by dwords.
--
regards
Aleksandr
|
|
| Back to top |
|
 |
Aleksandr Sharahov Guest
|
Posted: Tue May 31, 2005 6:52 am Post subject: Re: New Rule Suggestion |
|
|
Really the new functions increase size up
when Length mod 4 = 1, i.e. in 1/4 of all cases.
--
regards
Aleksandr
|
|
| Back to top |
|
 |
|
|
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
|
|