#initializing large array gives 'Address boundary error'

17 messages · Page 1 of 1 (latest)

gritty knot
#
#include <fstream>
#include <stdio.h>
#include <iostream>
using namespace std;

int main() {

        ifstream file("train-images-idx3-ubyte", ios::in | ios::binary);
        unsigned char pixel;
        int pixels[47040000];
        int i = 0;
        while(file.read(reinterpret_cast<char*>(&pixel),1)) {
                printf("%d\n", pixel);
                i++;
        }
        printf("\n\n%d", i); 
        file.close();

}

the int pixels[47040000] line is giving me the error. making the size smaller works, but I need it to be this size.

broken arrowBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

gritty knot
#

you can ignore all the other code.

#

I dont get why this is too large, as that is like 180 mb. and I have 8 gb of memory

#

'./a.out' terminated by signal SIGSEGV (Address boundary error)

grim shadow
#

Typically the stack has 1 to 8MB of memory, depending on OS and settings.

#

Make it static so it no longer resides on the stack or use an std::vector which uses the heap.

wicked echo
#

static will bloat your exec, so use vector

rustic light
tulip verge
#

is it not still the same size either way?

rustic light
#

because everything zero just becomes part of the .bss section

#

the executable doesn't literally store a bunch of zeros

tulip verge
#

right, but its still in the exe

rustic light
#

it just stores how large the bss section is in total

tulip verge
#

oh I see now, data in bss is not included in the exe

#

I was not aware of this before