From: hades Date: Thu, 9 Sep 1999 14:54:44 +0000 (+0000) Subject: avoid copies for realloc, event size has MAX now !!! X-Git-Url: https://jspc29.x-matter.uni-frankfurt.de/git/?a=commitdiff_plain;h=2f33522b7a39f3cd6d79af2610dc702080e31576;p=daqdata.git avoid copies for realloc, event size has MAX now !!! --- diff --git a/hadaq/evt.c b/hadaq/evt.c index b46ed60..1a74f09 100644 --- a/hadaq/evt.c +++ b/hadaq/evt.c @@ -1,4 +1,4 @@ -static char rcsId[] = "$Id: evt.c,v 6.1 1999-08-31 10:37:23 muench Exp $"; +static char rcsId[] = "$Id: evt.c,v 6.2 1999-09-09 14:54:44 hades Exp $"; #define _ANSI_C_SOURCE #include @@ -143,24 +143,19 @@ char *Evt_2charP(const void *my) void *newEvt(UInt4 decoding, UInt4 id, UInt4 runNr) { void *my; + static UInt4 seqNr = 0; + time_t tempo; + struct tm *gmTime; + UInt4 dummy; - my = allocMem(Evt_hdrSize()); + + my = allocMem(EVT_MAXSIZE); Evt_setSize(my, Evt_hdrSize()); Evt_setDecoding(my, decoding); Evt_setId(my, id); Evt_setRunNr(my, runNr); - return my; -} - -void *getEvt(void *my) -{ - static UInt4 seqNr = 0; - time_t tempo; - struct tm *gmTime; - UInt4 dummy; - Evt_setSeqNr(my, seqNr++); tempo = time(NULL); @@ -193,8 +188,6 @@ int Evt_write(void *my, FILE * file) void *Evt_appendSubEvt(void *my, void *subEvt) { - /* BUGBUG in principal, aligned memory size must be allocated */ - my = reallocMem(my, Evt_paddedSize(my) + SubEvt_size(subEvt)); memcpy(Evt_end(my), subEvt, SubEvt_size(subEvt)); Evt_setSize(my, Evt_paddedSize(my) + SubEvt_size(subEvt)); @@ -203,18 +196,12 @@ void *Evt_appendSubEvt(void *my, void *subEvt) void *Evt_fget(FILE * file) { - static void *evt = NULL; - - if (evt != NULL) { - freeMem(evt); - } - evt = allocMem(Evt_hdrSize()); + static void evt[EVT_MAXSIZE]; if (Evt_hdrSize() != fread(evt, 1, Evt_hdrSize(), file)) { msglog(LOG_DEBUG, "%s:%d: %s\n", __FILE__, __LINE__, strerror(errno)); return NULL; } - evt = reallocMem(evt, Evt_paddedSize(evt)); /* BUGBUG quickhack for a "Evt_paddedDataSize" */ if (Evt_paddedSize(evt) - Evt_hdrSize() != fread(Evt_data(evt), 1, Evt_paddedSize(evt) - Evt_hdrSize(), file)) { diff --git a/hadaq/evt.h b/hadaq/evt.h index e5d9f92..f644df8 100644 --- a/hadaq/evt.h +++ b/hadaq/evt.h @@ -8,6 +8,8 @@ #include "hadtu.h" #include "subevt.h" +#define EVT_MAXSIZE (100 * 1024) + static const int evtBlockSize = 8 * 1024; enum EvtId { @@ -55,7 +57,6 @@ UInt4 Evt_runNr(const void *my); void Evt_setRunNr(void *my, UInt4 runNr); void *newEvt(UInt4 decoding, UInt4 id, UInt4 runNr); -void *getEvt(void *my); void deleteEvt(void *my); int Evt_write(void *my, FILE * file); void *Evt_fget(FILE * file); diff --git a/hadaq/evtbuild.c b/hadaq/evtbuild.c index 29b9749..d982d19 100644 --- a/hadaq/evtbuild.c +++ b/hadaq/evtbuild.c @@ -1,4 +1,4 @@ -static char rcsId[] = "$Header: /misc/hadesprojects/daq/cvsroot/eventbuilder/hadaq/evtbuild.c,v 6.4 1999-09-06 07:33:14 hades Exp $"; +static char rcsId[] = "$Header: /misc/hadesprojects/daq/cvsroot/eventbuilder/hadaq/evtbuild.c,v 6.5 1999-09-09 14:54:44 hades Exp $"; #define _XOPEN_SOURCE #include @@ -280,7 +280,7 @@ int main(int argc, char *argv[]) evt = appendFile(evt, slowCtrlFiles[i]); } if (outFile != NULL) { - Evt_write(getEvt(evt), outFile); + Evt_write(evt, outFile); } deleteEvt(evt); @@ -337,8 +337,6 @@ int main(int argc, char *argv[]) } } if (currNrOfSubEvts == nrOfSubEvts) { - evt = getEvt(evt); /* BUGBUG differnce newEvt <> getEvt not - necessary any more */ if (outFile != NULL) { Evt_write(evt, outFile); } @@ -356,7 +354,7 @@ int main(int argc, char *argv[]) evt = appendFile(evt, slowCtrlFiles[i]); } if (outFile != NULL) { - Evt_write(getEvt(evt), outFile); + Evt_write(evt, outFile); } deleteEvt(evt);