Thread: struct and run-time error

  1. #1
    Registered User
    Join Date
    Aug 2005
    Posts
    80

    Question struct and run-time error

    I'm using Visual Studio 2005 to write a C/C++ program.

    I declare the following struct that contains an array:


    Code:
    typedef struct DataElement {
        char Fragment[45];
        double FragVal;
        int   NumFound;
        int FragID;
        char FragDisplay[45];
    } MetaFrag, ParaFrag, PhenOFrag,PhenPFrag;
    I call a function that creates a struct for MetaFrag,
    ParaFrag etc..(showing the MetaFrag Example):

    Code:
    MetaFrag *MF = NULL;
    MF = CreateMetaFile();
    //CreateMetaFile()
    MetaFrag *CreateMetaFile( void )
    { 
    
        MetaFrag *MF;
    
        MF = new DataElement [ 351 ];
        int n = 0;
        //0 - 10   
        strcpy(MF[n].Fragment,"R{A}CCCCCCC");
        strcpy(MF[n].FragDisplay,"CCCCCCC");
        MF[n].FragVal = -0.19; 
        MF[n].NumFound = 0; 
        MF[n].FragID = -1; n++;
        //etc..
        return( MF );
    }
    The program compiles fine, but it only works if I call 3 or
    less of the data elements.
    For example, I can call createmetafile, createparafile and
    create phenofile and it works fine. However, if I add the 4th call, create phenopfile, it blows up when I try to run it. I've switched the calls around to make sure it wasn't specific to the function being called.

    Does anyone see what I'm doing wrong? Any help is greatly appreciated

  2. #2
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    What's the run-time error message?
    Can it be a problem with memory fragmentation?
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  3. #3
    Registered User
    Join Date
    Aug 2005
    Posts
    80

    Thanks for getting back

    Right now, its compiled as a Coldfusion custom tag. It gives a generic message and then after a few seconds the following Windows error occures:
    Unhandled Win32 exception

    I think it may be a buffer overrun, so I'm going to create an executable quick to try and get more specific error message. Will get back once I find out more.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Try it in isolation, away from the rest of the code.

    Chances are, you've had a long-standing memory corruption problem which this code has just exposed, even though there is nothing wrong with this code (apparently).

    If it runs just fine in isolation, then the problem is somewhere else.

    If it crashes in isolation, then you have a nice small example to look at, which should be a lot easier to figure out as well.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User
    Join Date
    Aug 2005
    Posts
    80

    Isolated it

    Hey,

    Thanks for the info

    I created a separate executable that simply defines the struct and calls the
    functions. This runs fine so it must be a long-standing memory corruption problem. How would you recommend trouble-shooting that?

    Thanks again

    James

  6. #6
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    I suspect ColdFusion is limiting your access to memory on that tag. It's been a looong time since I last used ColdFusion. But I seem to recall you needing a special tag to run certain processes or needing to define some attributes... That's a big set of objects you are creating there.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  7. #7
    Registered User
    Join Date
    Aug 2005
    Posts
    80

    Looking into it

    Thanks for the info. It sound like Coldfusion may be the issue. I'm trimming down my arrays and put a post on Adobe about memory management. I'll let you know as I find out more.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Quantum Random Bit Generator
    By shawnt in forum C++ Programming
    Replies: 62
    Last Post: 06-18-2008, 10:17 AM
  2. sequential file program
    By needhelpbad in forum C Programming
    Replies: 80
    Last Post: 06-08-2008, 01:04 PM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  4. file & linked list run time error
    By Micko in forum C Programming
    Replies: 9
    Last Post: 03-06-2004, 02:58 AM
  5. Run Time Error
    By Unregistered in forum C Programming
    Replies: 4
    Last Post: 06-05-2002, 09:52 AM