Re: "Flex memory error" woes



In article <na.9aa3334dc5.a80520hsdawson@xxxxxxxxxxxx>, Howard Dawson
<hsdawson@xxxxxxxxxxxx> wrote:
> Anyone know what kind of failure usually causes this message or how I can
> get any further, as the error message is not very helpful and the program
> exits immediately on clearing it?

I had a similar problem with 'alloc' and free. You need to keep a very
careful check that a block of memory has actually been allocated before you
either free it or change it's size. To make absolutely sure I added code
which kept all allocated block pointers in an array and before
deleting/changing them I checked that there was a pre-recorded sensible
address at that location. (not forgetting to update the array! the pointer
may(will) change when the size is changed)

If it finds an error you can then call 'werr' or something similar to tell
you where the problem lies.

I also make a point of using 'sizeof' to check the size of anything I am
storing, rather than calculating it from the contents. (PS dont forget
to allow for string terminators).

It is symptomatic of bugs like this that they often cause problems much
later in the program - thus masking their source and making the hair tearing
effect rather more serious!!

NB I do let allocated arrays hold pointers - it seems to work although I
cannot see how!!!

NNB Can anyone provide an up to date description of the operation and
limitations of flex and alloc and the relationship between them? The only
description I know is in the old Acorn 'C' manual.

John


--
_ _________________________________________
/ \._._ |_ _ _ /' Orpheus Internet Services
\_/| |_)| |(/_|_|_> / 'Internet for Everyone'
_______ | ___________./ http://www.orpheusinternet.co.uk


.



Relevant Pages

  • Re: average problem
    ... says array declarations are covered on p. 22 and array ... initializations are covered on p. 86. ... those in the immediate vicinity of where your error message is ... I always thought pointers and arrays are interchangable. ...
    (comp.lang.c)
  • Re: Differance between Array and Pointers
    ... Well, except that arrays tend to be much larger than pointers, and the ... An array is a contiguous region of memory containing N elements of M ... indexing vs. a loop). ...
    (comp.arch.embedded)
  • [RFCv2][PATCH] flexible array implementation
    ... I call it a flexible array. ... storage for pointers to the second level. ... all locking must be provided by the caller. ... make sure to pass in &ptr instead of ptr. ...
    (Linux-Kernel)
  • [RFC][PATCH] flexible array implementation v4
    ... I call it a flexible array. ... so never does an order>0 allocation. ... storage for pointers to the second level. ... all locking must be provided by the caller. ...
    (Linux-Kernel)
  • Re: [RFC][PATCH] flexible array implementation v4
    ... I call it a flexible array. ... so never does an order>0 allocation. ... storage for pointers to the second level. ... all locking must be provided by the caller. ...
    (Linux-Kernel)