Re: Reading a string of unknown size



Anyway, your allocation strategy is very inefficient. Your calling
realloc() once every iteration of the loop. This could result in
fragmentation of the C library's memory pool. Why not allocate in terms
of fixed sized or dynamically growing blocks, say 128 bytes or so to
start with?

Very True, I agree with you.
I just wanted to give "Tonio Cartonio" the idea of how to do it.

.



Relevant Pages

  • Re: Reading a string of unknown size
    ... realloconce every iteration of the loop. ... fragmentation of the C library's memory pool. ... Why not allocate in terms ...
    (comp.lang.c)
  • Re: Memory problems (possibly very easy question)
    ... Now allocate 25,000 objects. ... Once you get the leaks fixed, fragmentation becomes your worst enemy. ... memory usage warnings. ... But releasing it does not reduce the footprint, it merely keeps it from growing as the ...
    (microsoft.public.vc.mfc)
  • Re: Matlab very slow with
    ... Do you preallocate cof before running the loop? ... I had no idea that Matlab had such issues ... allocating memory. ... Now you might ask why MATLAB can't automatically allocate the whole 100000 ...
    (comp.soft-sys.matlab)
  • Re: unknown problem
    ... The below code scans plane and find the nearest value to zero. ... allocate ) ... U2 is a loop invariant too. ...
    (comp.lang.fortran)
  • Re: Short-lived Objects - good or bad?
    ... that generally it is better to allocate and drop objects ... inside a loop, rather than allocate them before the loop ... person learned programming. ... I would be very surprised if effective GC of short lived objects ...
    (comp.lang.java.programmer)