0

As the title says, a project I've taken over has a static volatile struct that basically holds network data when connecting to a WiFi network. I need to create an array of these structs to save the data of previous networks.

This is what the struct I'm trying to copy looks like:

static volatile struct
{
    BYTE        MySSID[32]; 
    BYTE        SsidLength;             
    BYTE        SecurityMode;           
    BYTE        SecurityKey[32];           
    BYTE        SecurityKeyLength;
    BYTE        dataValid;
    BYTE        networkType;
    BYTE        IsLinked;
    BYTE        ConnectionID;
} NetworkStruct;

And this is the most recent of my failed attempts at creating an array that I can copy the data in this struct to:

static volatile struct
{
    BYTE        MySSID[32]; 
    BYTE        SsidLength;             
    BYTE        SecurityMode;           
    BYTE        SecurityKey[32];           
    BYTE        SecurityKeyLength;
    BYTE        dataValid;
    BYTE        networkType;
    BYTE        IsLinked;
    BYTE        ConnectionID;
} SavedNetworks[10];

So far, this and every other attempt throws an error.

Here is the error the above attempt throws:

Link Error: Could not allocate section .nbss, size = 944 bytes, attributes = bss near
Link Error: Could not allocate data memory

user3693406
  • 101
  • 8
  • 2
    http://stackoverflow.com/questions/15391996/mplab-link-error-could-not-allocate-section-c30-compiler – AnatolyS Oct 14 '15 at 12:31
  • Out of curiousity, what system is this? A bare metal microcontroller? Which one? – Lundin Oct 14 '15 at 12:53
  • The `volatile` makes no sense for your array. To make things proper declare your `struct` as a real type (without `volatile`), declare your one variable that is subject to unknown changes as volatile, and declare your array without `volatile`. And, why would you want your array to be `static`? Perhaps just a local variable in your function would suffice? – Jens Gustedt Oct 14 '15 at 13:17
  • This is a PIC microcontroller. Sorry, I'm relatively new to C and probably don't completely understand how volatile works so I'm looking into fixing that. I was basically just copying the way the first struct (which I did not write) was formatted because the whole point of this code is that whenever the module successfully connects to a network I need to add the details to a list of saved networks. If the module fails to connect to a network for more than 10 minutes, it spends 5 minutes attempting connection to each saved network before resetting. – user3693406 Oct 15 '15 at 18:55

1 Answers1

3

Link Error: Could not allocate section .nbss, size = 944 bytes

The linker failed to allocate the memory needed for the array in the .bss section, which is where all uninitialized static storage duration variables go. You are using too much memory for statics/globals, simple as that.

How to solve it depends on the specific system.

Lundin
  • 195,001
  • 40
  • 254
  • 396