Re: Strings

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Yes.

When allocating memory, there is *always* the possibility that the allocation will fail
and you will get a NULL pointer back. So assume that this is always possible.

APpending data to a string is a very expensive operation. Given you know the maximum size
of the string, this is a place where you might want to pre-allocate a buffer of 3MB and
just fill it. Whether or not you later convert it to a CString is yet a different
question.
joe

On Tue, 7 Nov 2006 03:16:02 -0800, Alamelu <Alamelu@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:

In one of the scenario, i need to keep on appending data to a string. The
final data size will be of 3 MB, (i.e) the string had to hold data of 3 MB,
the string had to be in memory util 3MB data is getting filled up

Will there be any risk or any crash happening?

Regards,
Alamelu N
Joseph M. Newcomer [MVP]
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.



Relevant Pages

  • Re: Implementing an interface
    ... pointer to pointer, which is supposed to contain the version number of ... I am not correctly allocating memory ... If the caller just expects a string with the version then you ...
    (comp.unix.programmer)
  • Re: Cant understand this! (Help required please)
    ... > If delete in pop deletes the nde, the new string that was pointed to by ... > node previously would still exist without a pointer had a string not ... you are allocating memory to hold the `data' that you are maintaining ... you are allocating memory to hold the structure for a node itself. ...
    (alt.comp.lang.learn.c-cpp)
  • Re: Pointers in delphi
    ... Yeah, I seem to have missed that bit. ... I disagree with your casting the string directly to a pointer, ...
    (alt.comp.lang.borland-delphi)
  • [patch 3/7] add kstrndup
    ... Add a kstrndup function, modelled on strndup. ... returns a string copied into its own allocated memory, ... * @s: the string to duplicate ... the GFP mask used in the kmalloccall when allocating memory ...
    (Linux-Kernel)
  • Re: core dump in stlport.so.1 provided by SUN studio
    ... Recently we were encountering weird core dump on our application. ... It crashed in allocating memory for constructing a string. ...
    (comp.unix.solaris)