struct and run-time error

This is a discussion on struct and run-time error within the C++ Programming forums, part of the General Programming Boards category; I'm using Visual Studio 2005 to write a C/C++ program. I declare the following struct that contains an array: Code: ...

  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
    Portugal
    Posts
    7,412
    What's the run-time error message?
    Can it be a problem with memory fragmentation?
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,452
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  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
    Portugal
    Posts
    7,412
    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.
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    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, 01:58 AM
  5. Run Time Error
    By Unregistered in forum C Programming
    Replies: 4
    Last Post: 06-05-2002, 09:52 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21