This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

SEGMENT TOO LARGE

Hi,
first of all, thanks a lot to Dan Henry and Drew Davis for their answers about generic pointers.

And now my problem is: compiling this dummy code I get the following error:

void tst_mem_large() large
{
   { char data buf [128] = ""; }
   { char data buf [128] = ""; }
}

...error C249: 'DATA': SEGMENT TOO LARGE


But why is there NO ERRORS in this sample?

void tst_mem_small() small
{
   { char data buf [128] = ""; }
   { char data buf [128] = ""; }
}

... 0 Error(s), 0 Warning(s).


Thank you.

  • That's a good question!

    Maybe the compiler is managing to Overlay the buffers in the 2nd case?
    You should be able to see this in the Compiler and/or Linker Listing files.

    It does, however, leave the question of why it couldn't do it in the 1st case...

    Looks like some more ammunition for Erik's "never use LARGE model" campaign, though...

    ;-)

  • Ok, a couple more examples:

    void tst_mem_pdata_small() small
    {
       { char pdata buf [256] = ""; }
       { char pdata buf [256] = ""; }
    }
    ... error C249: 'PDATA': SEGMENT TOO LARGE
    

    void tst_mem_pdata_compact() compact
    {
       { char pdata buf [256] = ""; }
       { char pdata buf [256] = ""; }
    }
    ... 0 Error(s), 0 Warning(s).
    

    void tst_mem_pdata_large() large
    {
       { char pdata buf [256] = ""; }
       { char pdata buf [256] = ""; }
    }
    ... error C249: 'PDATA': SEGMENT TOO LARGE
    


    It seems that only the corresponded to current memory model local variables may be overlayed (data - small, pdata - compact, xdata - large)...

  • Did you check out the theory about the Overlaying?

    It looks like it's only Overlaying objects that are specifically located in the particular model's "own" memory space...?

  • I'd send this example to Keil support via email. (This forum isn't an official method of support, though Keil employees to read messages and respond.)

    I suspect the compiler is being challenged in this case :)

    I had run some experiments on block declarations with version 7, and found that the compiler did not take advantage of that information for overlaying. Essentially the variables were all promoted out of their block and existed at the level of the enclosing function. Perhaps version 8 has more capabilities in this regard.

    But the memory model shouldn't make a difference. In one case, the memory qualifer ("data") matches the default for the memory model, and in the other, it does not. (The experiment of declaring the variables "xdata" and seeing if they overlay in either or both cases suggests itself. Perhaps the overlaying only occurs with small model, or perhaps it only occurs when the memory qualifers match, or perhaps something else.)

  • "I had run some experiments on block declarations with version 7, and found that the compiler did not take advantage of that information for overlaying."

    Yes, that was mentioned in the forum some time back...