Re: New Rule Suggestion



On Mon, 30 May 2005 20:05:10 +0200, "Dennis"
<marianndkc@xxxxxxxxxxxxxxx> wrote:

>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
.



Relevant Pages

  • Re: Blowfish encryption
    ... the source string will be padded to the next ... correct for Harbour/HWGUI but for good old 16 bit Clipper it ... allocate up to 64K, so any data/field longer than this will fail. ... an unrecoverable error 5304 (conventional memory exhausted). ...
    (comp.lang.clipper)
  • Re: Function speed, which is fast
    ... what is happening is the string is getting resized and memory allocation ... or you could create a dynamic memory chuck pointed via a PCHAR.. ... allocate like a 100K byte Pchar buffer. ... > function examines every single character of the plain text file. ...
    (comp.lang.pascal.delphi.misc)
  • Re: This is getting really weird.
    ... I thought 4 bytes for reference count and 4 for string length. ... > There should be no memory allocation for that line. ... > manager may allocate more space than requested for its own efficiency. ... > that New returned with a pointer to the string constant. ...
    (alt.comp.lang.borland-delphi)
  • Re: Unknown Crashing...
    ... each) and allocate that much memory. ... if the string given for Station is sizeofor more ... This copies the string from the Station array to itself. ...
    (comp.lang.c.moderated)
  • Re: Fast string operations
    ... Looping: I thought looping over arrays in managed code was "slow" ... array handling and such. ... The problem with TrimHelper is that it always returns a new string instance. ... The customer perceives this as a memory leak. ...
    (microsoft.public.dotnet.languages.csharp)