Author Topic: Mathomatic Port to Ndless gives a memory error  (Read 18180 times)

0 Members and 1 Guest are viewing this topic.

Offline Vogtinator

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1193
  • Rating: +108/-5
  • Instruction counter
    • View Profile
Re: Mathomatic Port to Ndless gives a memory error
« Reply #15 on: May 07, 2014, 01:05:39 pm »
There has to be something else that fails. That block allocates less than 10KB, so it can't be the reason.

Offline quadratic77

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 16
  • Rating: +0/-0
    • View Profile
Re: Mathomatic Port to Ndless gives a memory error
« Reply #16 on: May 07, 2014, 01:09:15 pm »
Any ideas? It fails at that block of code, so I expected it was malloc's fault.

Offline Vogtinator

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1193
  • Rating: +108/-5
  • Instruction counter
    • View Profile
Re: Mathomatic Port to Ndless gives a memory error
« Reply #17 on: May 07, 2014, 01:10:38 pm »
The breakpoint at malloc was intentional, to track every single allocation the program tries.

Offline quadratic77

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 16
  • Rating: +0/-0
    • View Profile
Re: Mathomatic Port to Ndless gives a memory error
« Reply #18 on: May 07, 2014, 01:22:39 pm »
It's not a breakpoint, it's a return value. The original function:

int
init_mem(void)
{
    if (n_tokens <= 0)
        return false;
    if ((scratch = (token_type *) malloc(((n_tokens * 3) / 2) * sizeof(token_type))) == NULL
        || (tes = (token_type *) malloc(n_tokens * sizeof(token_type))) == NULL
        || (tlhs = (token_type *) malloc(n_tokens * sizeof(token_type))) == NULL
        || (trhs = (token_type *) malloc(n_tokens * sizeof(token_type))) == NULL) {
        return false;
    }
    if (alloc_next_espace() < 0) {    /* make sure there is at least 1 equation space */
        return false;
    }
    clear_all();
    return true;
}

I edited the return values to be 1,  (((n_tokens * 3 )/ 2 ) * sizeof(token_type)), 3, and 0, respectively, and edited the function that init_mem(); returned to so it would print the return values, and continue without error if the value was 0. Therefore I could track where the fail was coming from.

I don't think the "breakpoint" was intentional: it was in the code to begin with. Maybe I'm misunderstanding you.

Offline Vogtinator

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1193
  • Rating: +108/-5
  • Instruction counter
    • View Profile
Re: Mathomatic Port to Ndless gives a memory error
« Reply #19 on: May 07, 2014, 01:25:38 pm »
No, I meant
Quote
Instead of putting a breakpoint in malloc I did this:

It'd be really helpful to know how much it's trying to allocate where.

Offline quadratic77

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 16
  • Rating: +0/-0
    • View Profile
Re: Mathomatic Port to Ndless gives a memory error
« Reply #20 on: May 07, 2014, 01:29:22 pm »
Didn't I find how much it was allocating (2400)? (and breakpoints don't do me much good seeming as I've never figured out how to use a debugger very well)

Offline Vogtinator

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1193
  • Rating: +108/-5
  • Instruction counter
    • View Profile
Re: Mathomatic Port to Ndless gives a memory error
« Reply #21 on: May 07, 2014, 01:32:13 pm »
Yes, but that't can't fail. In crafti I'm allocating much more than 320*240*2*2=307200.
Either something is completely broken (very unlikely, though possible) or it does some huge mallocs earlier on.

Offline quadratic77

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 16
  • Rating: +0/-0
    • View Profile
Re: Mathomatic Port to Ndless gives a memory error
« Reply #22 on: May 07, 2014, 01:54:46 pm »
Just to make sure I didn't mess something up by changing things I re-built the source with no modifications except for changing printf in the example to nspireio's functions, setting up console, etc. It still gave "Not enough memory.".

No mallocs that I can find earlier on...all it does it make a couple of variables, setup the global variables, etc. Nothing big, and no mallocs that I can see.

Oh, and crafti is very nice ;) amazed at how fast it goes.

Offline Vogtinator

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1193
  • Rating: +108/-5
  • Instruction counter
    • View Profile
Re: Mathomatic Port to Ndless gives a memory error
« Reply #23 on: May 07, 2014, 01:56:54 pm »
Then debugging is your best bet. How big is the executable file?

Offline quadratic77

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 16
  • Rating: +0/-0
    • View Profile
Re: Mathomatic Port to Ndless gives a memory error
« Reply #24 on: May 07, 2014, 02:16:53 pm »
336K to 435K, I have no idea why it changes when I make a very small addition or subtraction.

As for debugging, how? gdb?

Offline Vogtinator

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1193
  • Rating: +108/-5
  • Instruction counter
    • View Profile
Re: Mathomatic Port to Ndless gives a memory error
« Reply #25 on: May 07, 2014, 02:57:55 pm »
Quote
336K to 435K, I have no idea why it changes when I make a very small addition or subtraction.
100K is a huge difference. Probably it's printf or something else that requires a lot of external stuff.

Quote
As for debugging, how? gdb?
Yup, http://ndlessly.wordpress.com/debugging-with-gdb/ or with any other gdb compatible IDE or even GDB itself. Don't forget to compile with "-g -Og"!