Re: memory problem?

From: Chiara Zampolli <Chiara.Zampolli_at_bo.infn.it>
Date: Thu, 23 Nov 2006 15:32:50 +0100


PS: obviously, I miscalled chiara.cxx as a class, but it is a main....

Chiara Zampolli wrote:
> Dear rooters,
>
> I think I have some problems with memory allocation in compiling a
> class (or something like this), and I really hope you could help me...
> You can find a simplified version of my class in the attached file
> chiara.cxx, which is to be compiled with the attached MakefileSimple.
> As you can see, the compilation succeeds, but then, when you try to
> run the executable, you get a "segmentation fault" error:
>
> [zampolli_at_pctof1 Chiara]$ ./chiara
> Segmentation fault
> [zampolli_at_pctof1 Chiara]$
>
> (to be noted that this happens also if the "if" of line 17 is not
> commented, so if the array - on which the problem may depend - should
> not be created during the execution...). On the contrary, this does
> not happen if I set the size variable to 1600, or if I use a macro
> (test.C) within a root session (instead of the executable "chiara").
> Could you please help me in understanding the problem?
> I am using the root v5-13-04 version, on a SL 4.2 pc.
>
> Thank you a lot.
> Best Regards,
>
> Chiara
>
> ------------------------------------------------------------------------
>
> #---------------------------------------------------------------------
> #
> #
> TARGET := chiara
> SOURCES := chiara.cxx
> #BINS := chiara chiara.sh
>
> #---------------------------------------------------------------------
> # you shouldn't need to change anything below this line.
> #
> OBJECTS := $(TARGET).o $(filter-out $(TARGET).o, \
> $(filter %.o, $(SOURCES:%.cxx=%.o)) \
> $(filter %.o, $(SOURCES:%.c=%.o)))
>
> #---------------------------------------------------------------------
> # Third party libraries
> #
> ROOT_CFLAGS := $(filter-out -I% -D%, $(shell root-config --cflags))
> ROOT_CPPFLAGS := $(filter-out $(ROOT_CFLAGS), $(shell root-config --cflags))
> ROOT_LDFLAGS := $(filter-out -l%, $(shell root-config --libs))
> ROOT_LIBS := $(filter -l%, $(shell root-config --libs)) -lNew -lVMC -lGeom -lEG -lMinuit
>
> #---------------------------------------------------------------------
> # Compilers and such
> #
> CPP := g++ -E
> CPPFLAGS := $(ROOT_CPPFLAGS)
> CC := gcc -c
> CFLAGS := $(ROOT_CFLAGS)
> CXX := g++ -c
> CXXFLAGS := $(CFLAGS)
> LD := g++
> LDFLAGS := $(ROOT_LDFLAGS)
> LIBS := $(ROOT_LIBS)
>
> #---------------------------------------------------------------------
> # Pattern rules
> #
> %.o:%.cxx
> $(CXX) $(CPPFLAGS) $(CXXFLAGS) $<
>
> %.o:%.c
> $(CC) $(CPPFLAGS) $(CFLAGS) $<
> %:%.o
> $(LD) $^ $(LDFLAGS) $(LIBS) -o $@
>
> #---------------------------------------------------------------------
> # Targets
> all: $(TARGET)
>
> clean:
> rm -rf $(TARGET) $(OBJECTS)
>
> show:
> @echo "TARGET : $(TARGET)"
> @echo "SOURCES : $(SOURCES)"
> @echo "OBJECTS : $(OBJECTS)"
> @echo "-----------------"
> @echo "ROOT_CPPFLAGS : $(ROOT_CPPFLAGS)"
> @echo "ROOT_CFLAGS : $(ROOT_CFLAGS)"
> @echo "ROOT_LDFLAGS : $(ROOT_LDFLAGS)"
> @echo "ROOT_LIBS : $(ROOT_LIBS)"
> @echo "-----------------"
> @echo "CPP : $(CPP)"
> @echo 'CPPFLAGS : $(CPPFLAGS)'
> @echo "CXX : $(CXX)"
> @echo 'CXXFLAGS : $(CXXFLAGS)'
> @echo "LD : $(LD)"
> @echo "LDFLAGS : $(LDFLAGS)"
> @echo "LIBS : $(LIBS)"
>
> $(TARGET):$(OBJECTS)
>
>
> #---------------------------------------------------------------------
> #
> # EOF
> #
>
>
>
> ------------------------------------------------------------------------
>
>
> #include <Riostream.h>
> #include <stdio.h>
> #include <stdlib.h>
>
> #include "TFile.h"
> #include "TTree.h"
> #include "TKey.h"
> #include "TFile.h"
>
> //int main(int argc, char **argv){
> int test(){
> // static const Int_t size=1600;
> static const Int_t size=16000;
> static const Int_t nbins=1500;
> Short_t tofarray[size][nbins];
> TFile *fileout = new TFile("outArrayC.root","OPEN");
> cout << " qui ok inzio fileout = " << fileout << endl;
> TTree * tree = 0x0;
> TIter next(fileout->GetListOfKeys());
> TKey *key;
> while ((key=(TKey*)next())){
> cout << " loooooop over keys.... " << endl;
> const char * namekey = key->GetName();
> if (strcmp(namekey,"T")==0){
> cout << " found tree " << endl;
> tree = (TTree*) fileout->Get("T");
> break;
> }
> }
> fileout =0x0;
> delete fileout;
> tree =0x0;
> delete tree;
> key =0x0;
> delete key;
>
> return 1;
> }
> ------------------------------------------------------------------------
>
>
> #include <Riostream.h>
> #include <stdio.h>
> #include <stdlib.h>
>
> #include "TFile.h"
> #include "TTree.h"
> #include "TKey.h"
> #include "TFile.h"
>
> int main(int argc, char **argv){
> //int ciccino(){
> // static const Int_t size=1600;
> static const Int_t size=16000;
> static const Int_t nbins=1500;
> Int_t flag=0;
> //if (flag !=0){
> Short_t tofarray[size][nbins];
> //}
> TFile *fileout = new TFile("outArrayC.root","OPEN");
> cout << " qui ok inzio fileout = " << fileout << endl;
> TTree * tree = 0x0;
> TIter next(fileout->GetListOfKeys());
> TKey *key;
> while ((key=(TKey*)next())){
> cout << " loooooop over keys.... " << endl;
> const char * namekey = key->GetName();
> if (strcmp(namekey,"T")==0){
> cout << " found tree " << endl;
> tree = (TTree*) fileout->Get("T");
> break;
> }
> }
> fileout =0x0;
> delete fileout;
> tree =0x0;
> delete tree;
> key =0x0;
> delete key;
>
> return 1;
> }
Received on Thu Nov 23 2006 - 15:24:00 MET

This archive was generated by hypermail 2.2.0 : Mon Jan 01 2007 - 16:32:02 MET