-2

I am dealing with NI DAQmx and they define unsigned long as uInt32. I declare uInt32 array [1048*1024] in the header file and it compiles, but when I try to run it, it seems to freeze, and when I stop it, it exits with an error:

The program has unexpectedly finished.
D:\Projects\build-BlackAndWhite12bit-Desktop_Qt_5_1_1_MinGW_32bit-Debug\debug\BlackAndWhite12bit.exe exited with code -1073741571

Well, it does not say that there is not enough memory, but since I allocate 4*1048*1024 = 4,292,608 bytes, and my version is Qt Creator 2.8.1 Based on Qt 5.1.1 (MSVC 2010, 32 bit) on Win7 x64, I expect it to not have enough memory.

I found a similar question Qt Creator - calloc fails with large memory, but the only solution that works for me, would be, probably, moving to 64bit. But how do I do that? I tried to download the application from this website with the Qt 5.2.1 for Windows 64-bit (VS 2012, 556 MB) link. But when I got it, it seems to be a 32bit version configured for 64bit. Is this the one I need? Do I need OpenGL?

Is there a way to allow more memory for my current Qt version? Any other ways to go around my problem?

Here's the .h content:

#ifndef MAIN12BITSAMPLING_H
#define MAIN12BITSAMPLING_H

#include <QMainWindow>
#include "nivision.h"
#include "nivis.h"
#include "NIDAQmx.h"

namespace Ui {
class main12bitSampling;
}


class main12bitSampling : public QMainWindow
{
    Q_OBJECT

public:
    explicit main12bitSampling(QWidget *parent = 0);
    ~main12bitSampling();

...
uInt32          ddata[1073152];
...

signals:


private slots:


private:
   Ui::main12bitSampling *ui;
};

#endif // MAIN12BITSAMPLING_H

Here's the main.c:

#include "main12bitsampling.h"
#include <QApplication>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    main12bitSampling w;
    w.show();
    return a.exec();
}

And here's the main12bitsampling.cpp:

main12bitSampling::main12bitSampling(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::main12bitSampling)
{
ui->setupUi(this);
mainLoop();

}

main12bitSampling::~main12bitSampling()
{
     delete ui;
}
Community
  • 1
  • 1
Nazar
  • 820
  • 5
  • 13
  • 36
  • You're dealing with ~4Mb allocation, that's tiny. That's way below the limits of 32bit processes (4Gb theoretical). You'll need to debug that piece of code to figure out what it's doing, switching to 64bit just isn't necessary here. – Mat May 16 '14 at 15:28
  • 1
    @Mat unless that is on the stack, those have much smaller limits than the heap – ratchet freak May 16 '14 at 15:42
  • How are you instantiating `main12bitSampling`? My guess is on the stack, which has less than 4MB of room available by default. Switching to heap allocation will fix it. – nobody May 16 '14 at 15:44
  • @Mat I just added the content of .h file. I do not do anything with _ddata_ yet. It's only declared in .h file. And as I said before, the program compiles with no problems, but does not run properly. What to debug, if I do not really have any actions associated with that variable? – Nazar May 16 '14 at 15:45
  • That's not enough code. You need to show how you're allocating instances of that class. – Mat May 16 '14 at 15:47
  • @ratchetfreak: indeed. But switching to 64bit wouldn't help with that either (AFAIK - unless there's a default stack size that's larger for 64bit processes I guess) – Mat May 16 '14 at 15:48
  • @AndrewMedico Unfortunately, I do not know how I initialize it. Could you, please, explain how to switch to a heap? Is it somewhere in the settings? – Nazar May 16 '14 at 15:49
  • @Naz switching it tot he heap means changing how you declare it, Check the main.cpp in sources, however my answer below is a better solution. – ratchet freak May 16 '14 at 15:51
  • @Mat Just added more code – Nazar May 16 '14 at 15:55

1 Answers1

1
-1073741571==0xc00000fd

and c00000fd is the error code for a stack overflow.

Keeping such large arrays statically where it can end up on the stack is problematic, allocate it on the heap and you will be much better off:

QVector<uInt32>          ddata;

main12bitSampling::main12bitSampling(QWidget *parent = 0)
    QMainWindow(parent), ddata(1024*1048)
{
    //...
}
ratchet freak
  • 47,288
  • 5
  • 68
  • 106
  • When I add _QVector ddata;_ to my .h file and _ddata(1024*1048)_ to the constructor as you suggested, I get an conversion error saying that 'cannot convert 'QVector' to 'uInt32* {aka long unsigned int*}' for argument '5' to 'int32'' When I just do _uInt32 ddata_, I get 'invalid conversion from 'uInt32 {aka long unsigned int}' to 'uInt32* {aka long unsigned int*}' It looks like I MUST have my array pointer defined as uInt32. – Nazar May 16 '14 at 16:19
  • to access the data you need to do `ddata.data()` this returns a uInt32* that you can pass instead of the array – ratchet freak May 16 '14 at 16:26
  • @hyde in this case it was on the stack – ratchet freak May 16 '14 at 18:06
  • If it was kept statically, it would not be in stack. – hyde May 16 '14 at 18:14
  • @ratchetfreak Still can not get it to work. So, I declare **QVector ddata;** in the .h file. Then I allocate memory in the constuctor by adding **ddata(1024*1048),** after **QMainWindow(parent)** as in your answer. And then I pass the pointer to the DAQmx function as **ddata.data()**? But when I want to read the content of the array I perform **ddata.value(n)** right? – Nazar May 16 '14 at 19:17
  • @ratchetfreak Got it! I truly appreciate your help. – Nazar May 16 '14 at 20:26