• Using OS_DynamicArea to roll my own memory allow & free routines.

    From usenet@garethlock.com@21:1/5 to All on Thu Mar 26 12:56:13 2020
    Been trying to use malloc() and free() from C to create buffers for loading files... Once I've loaded and unsquashed one Sprite file, even if I return the file buffer (squashed data) back to the system, I seem unable to load more than one file before I
    overwrite the heap...

    Is this something I'm doing wrong, or a limitation of malloc()? If it is indeed the second, can someone point me to an equivalent or some way of increasing this memory pool...

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Matthew Phillips@21:1/5 to usenet@garethlock.com on Fri Mar 27 12:47:07 2020
    In message <38b1b34d-d309-49ee-9116-6402b22444f5@googlegroups.com>
    on 26 Mar 2020 usenet@garethlock.com wrote:

    Been trying to use malloc() and free() from C to create buffers for loading files... Once I've loaded and unsquashed one Sprite file, even if I return the file buffer (squashed data) back to the system, I seem unable to load more than one file before I overwrite the heap...

    What environment is your program running in. Is it a Wimp application? Is
    it a command-line program running in a TaskWindow, or what?

    If you are running in a TaskWindow, you might need to increase the Next slot
    in the Wimp *before* you open the TaskWindow.

    Is this something I'm doing wrong, or a limitation of malloc()?

    Definitely something you are doing wrong!

    By the way, your subject line is "Using OS_DynamicArea to roll my own memory allow & free routines", but you don't seem to have said anything about this
    in your posting. Is OS_DynamicArea relevant to your question?

    --
    Matthew Phillips
    Durham

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From usenet@garethlock.com@21:1/5 to All on Fri Mar 27 07:05:51 2020
    I'm running as a fullscreen single tasking app. What I'm trying to write is a C port of Brix. I've come to the conclusion that trying to implement all the features I have planned for this in BASIC is going to run way too slow. So I'm currently trying to
    re-implement this thing in C.

    I have various test programs up and running, including timers, squash decompression, handling of TimPlayer from within C, reading mouse state etc. Indeed, I can get as far as displaying the loading screen with music. As soon as I proceed to load and
    decompress the other two Sprite files I come unstuck with "unrecoverable error in the run time system : Not enough memory, malloc failed, (heap overwritten)"

    I've given myself a Next slot of 189952K, but this makes no difference at all...

    I have three routines that make up the memory system...

    void * mem_alloc(size_t s) {
    size_t * ret = malloc(sizeof(size_t) + s);
    *ret = s;
    return &ret[1];
    };

    void mem_free(void * ptr) {
    free((size_t*)ptr - 1);
    };

    size_t mem_size(void * ptr) {
    return ((size_t*)ptr[-1];
    };

    This is to allow me to return the size of the allocated space.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Matthew Phillips@21:1/5 to usenet@garethlock.com on Fri Mar 27 17:34:04 2020
    In message <f18e2353-8d3f-4252-a4f7-daa330b327ae@googlegroups.com>
    on 27 Mar 2020 usenet@garethlock.com wrote:

    As soon as I proceed to load and decompress the other two Sprite files I
    come unstuck with "unrecoverable error in the run time system : Not enough memory, malloc failed, (heap overwritten)"

    I've given myself a Next slot of 189952K, but this makes no difference at all...

    Most likely what is happening is that you are writing beyond the bounds of a block of allocated memory and overwriting the pointers that are used by the heap system to maintain its linked list of allocated memory.

    This kind of error is very common if you make mistakes. It usually doesn't mean that you have run out of memory, but that the heap has been corrupted.

    A tool like Fortify can be compiled into your code to help you track down
    where the fault is.

    Matthew

    --
    Matthew Phillips
    Durham

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From usenet@garethlock.com@21:1/5 to All on Fri Mar 27 12:30:19 2020
    Ok... Where can I get a copy??

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Matthew Phillips@21:1/5 to usenet@garethlock.com on Sat Mar 28 12:22:32 2020
    In message <b58d5245-6108-461a-8fbc-eb2dbc686744@googlegroups.com>
    on 27 Mar 2020 usenet@garethlock.com wrote:

    Ok... Where can I get a copy??

    https://github.com/dpt/PrivateEye/blob/master/libs/fortify/FortifyDoc

    --
    Matthew Phillips
    Durham

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From usenet@garethlock.com@21:1/5 to All on Sat Mar 28 08:20:23 2020
    Ok... I've found it, but how the heck do I download it from there as a zip... I've tried to clone it from git on a pc and failed... Short of pulling each file individually...

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From usenet@garethlock.com@21:1/5 to All on Sat Mar 28 08:24:43 2020
    Scratch that....

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From usenet@garethlock.com@21:1/5 to All on Sat Apr 4 16:52:12 2020
    Ok... Got far enough today to confirm that mem_free() as defined in my second post to this topic is not freeing the allocation properly. Still trying to figure out what exactly is going on.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)