Thread: BCC32 Memory Issue

  1. #1
    Registered User
    Join Date
    Aug 2004
    Posts
    19

    BCC32 Memory Issue

    Hi Guys

    I just downloaded he Bcc32 complier from Borland, Installed and set up the default option in the readme file

    Then I got down to some coding

    I have the complier running on Windows 2000 platform and running it under the command prompt nothing unusual I hope

    The problem I seem to have is when I generate a large array using a for loop and process the data I can only use a small array ie 100 100 10 when I increase the size I get a program error and an error log has been generated (cant find where this is stored)

    When I run a "mem" on my system I have 1MB total contiguous extended memory and 0 MB (zero) byte available contiguous extended memory (see attachment)

    Can n e one shed some light on this I can see where I can go from here as DOS windows doesn?t allow you to increase memory

    I've also tried using malloc() function to set the memory but i still get the same error(crash)

    Here is the code using the malloc () function


    Code:
     /*Snippet of code creates a 3D array*/
    //Working version better that datacamera
    
    
    #include "stdlib.h"
    #include "stdio.h"
    #include "math.h"
    #include "time.h"
    
    #include "windows.h"
    
    
    /* Defining the dimension of the datacamera array*/
    #define NoOfFrames 20
    #define XDim 500   // this means X rows
    #define YDim 500   // this means Y rows
    #define size 2
    #define index 0
    
    main()
    {
    
    //printf("No Problem");
    
    /*Initialisng the LOOP values x y and FrameNoDepth coordinates for the array*/
    int i, j, FrameNoDepth,numberint;
    double number;
    int StartCount,EndCount,ResultCount;
    
    printf("No Problem");
    
    
    // Defines the datacamera array NOTE change to the datacamera that appears within the FOR loop
    int *datacamera [NoOfFrames] [XDim] [YDim];
    int *TotalDiff [size] [XDim] [XDim];
    int *Diff [size] [XDim] [XDim];
    
    
    
    datacamera [NoOfFrames] [XDim] [YDim] = malloc(2000000);
    TotalDiff [size] [XDim] [XDim] = malloc(2000000);
    Diff [size] [XDim] [XDim] = malloc(2000000);
    
    
    if (!datacamera){
            printf("Allocation Error");
            exit(1);
            }
    
    if (!TotalDiff){
            printf("Allocation Error");
            exit(1);
    	}
    
    
    if (!Diff){
            printf("Allocation Error");
            exit(1);
    	}
    
    
    
    
    
    //***********************************************************
    //*              Code to View GENERATE DATA                 *
    //***********************************************************
    
    for (FrameNoDepth=0;FrameNoDepth<=(NoOfFrames-1);FrameNoDepth++){
    	for (i=0;i<=(XDim-1);i++){     // rows defined first
    	for (j=0;j<=(YDim-1);j++){     // then coloums
    
            if (FrameNoDepth==0){
            datacamera[FrameNoDepth][i][j] = 0;
    
    	}
            else{
            *datacamera[FrameNoDepth][i][j] = i;
    
    	}
    
    
    	}/*end j for loop*/
     }/*end i for loop*/
    } /*end FrameNoDepth for loop*/
    
    // initialise SUM of DIFFERENCE array
    
    	for (i=0;i<=(XDim-1);i++){     // rows defined first
    	for (j=0;j<=(YDim-1);j++){     // then coloums
    
            TotalDiff[index][i][j] = 0;
    
    	}/*end j for loop*/
     }/*end i for loop*/
    
    // initialise SUM of DIFFERENCE array
    
    	for (i=0;i<=(XDim-1);i++){     // rows defined first
    	for (j=0;j<=(YDim-1);j++){     // then coloums
    
            Diff[index][i][j] = 0;
    
    	}/*end j for loop*/
     }/*end i for loop*/
    
    
    
    //***********************************************************
    //*                  Code to View ANALYSE                   *
    //***********************************************************
    
    // Code to start the clock
    StartCount = GetTickCount();
    
    for (FrameNoDepth=0;FrameNoDepth<=(NoOfFrames-1);FrameNoDepth++){
    	for (i=0;i<=(XDim-1);i++){     // rows defined first
    	for (j=0;j<=(YDim-1);j++){     // then coloums
    
            //Line below calculate the difference using the first image in the array index=0
            *Diff[index][i][j] = abs(*datacamera[index][i][j]-*datacamera[FrameNoDepth][i][j]);
            *TotalDiff[index][i][j] = *TotalDiff[index][i][j] + *Diff[index][i][j];
    
    	}/*end j for loop*/
     }/*end i for loop*/
    } /*end FrameNoDepth for loop*/
    
    
    EndCount = GetTickCount();
    
    
    //***********************************************************
    //*                   Code to View DATA                     *
    //***********************************************************
    
    printf("--------------- \n");
    
    
    printf("\n");
    ResultCount = EndCount-StartCount;
    printf("Count, %d",ResultCount);
    
    //Free up memory location
    free (datacamera);
    free (TotalDiff);
    free (Diff);
    
    return 0;
    
    
    
    
    }
    Last edited by Salem; 08-02-2004 at 06:27 AM. Reason: Tagging!!!

  2. #2
    Registered User
    Join Date
    Mar 2003
    Posts
    143
    OK, first things first. Use code tags and use indentation. If you don't know what I'm
    talking about then read the << !Posing Code? Read this First !! >> thread. It really
    does apply to you as well...

    main() should be int main (void)
    Code:
      int *datacamera [NoOfFrames] [XDim] [YDim];
      int *TotalDiff [size] [XDim] [XDim];
      int *Diff [size] [XDim] [XDim];
    I reckon you need about 24 million bytes for these three arrays which is quite
    a lot to store on the stack! Try assigning it as global - this way memory is allocated
    on the heap rather than on the stack (that's probably not true in all cases but it works
    on all the compilers I've used where I've had this type of problem)

    Think about this code as well. You are assigning outside of the array range, (numbering
    starts from 0)
    Code:
      datacamera [NoOfFrames] [XDim] [YDim] = malloc(2000000);
      TotalDiff [size] [XDim] [XDim] = malloc(2000000);
      Diff [size] [XDim] [XDim] = malloc(2000000);
    I didn't get much further than this in the code. To be honest I couldn't be bothered
    wading any further...
    DavT
    -----------------------------------------------

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Like DavT says, your attempt at allocating multi-dimensional arrays is badly broken
    There are numberous examples of how to do this on the board.

    > #include "stdlib.h"
    Should use <> for standard headers
    #include <stdlib.h>

    > #include "windows.h"
    I see no reason for including this header file

    > main()
    make this explicitly return int, as
    int main()

    > When I run a "mem" on my system I have 1MB total contiguous extended memory
    This only applies to true 16 bit DOS programs.
    Fortunately for you, bcc55 generates 32 bit console programs, which have access to a bit more memory than that.

    > printf("No Problem");
    > int *datacamera [NoOfFrames] [XDim] [YDim];
    Now you're mixing C and C++ (the result being C++)
    Declarations precede statements in C - they cannot be mixed yet.
    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.

  4. #4
    Quote Originally Posted by Salem
    Declarations precede statements in C - they cannot be mixed yet.
    Actually, they can, if the compiler supports C99.
    Emmanuel Delahaye

    "C is a sharp tool"

  5. #5
    Registered User
    Join Date
    Aug 2004
    Posts
    19
    By the looks of it I'd probably be better off starting from scratch again

    someone told me that i should use
    Code:
    new int
    and

    Code:
    delete
    as there are more up to date than using the malloc function
    Last edited by sononix; 08-02-2004 at 07:43 AM.

  6. #6
    Registered User
    Join Date
    Jul 2004
    Posts
    101
    Quote Originally Posted by Emmanuel Delaha
    Actually, they can, if the compiler supports C99.
    The question was concerning Borland's free compiler, which does not support C99. Also, C99 compliant compilers are rare enough that for practical use, C89/90 should be assumed unless otherwise specified by the original poster. Though this is just my opinion, it makes more sense than confusing people with features that they are unable to use.

    @sononix:

    Those features are unique to C++, C does not support memory management though new and delete keywords. Your only options for portable C are malloc, calloc, realloc and free.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need Help finding potential Memory issue
    By JoshNCSU22 in forum C Programming
    Replies: 9
    Last Post: 10-29-2008, 09:58 AM
  2. What's the difference?
    By Stonehambey in forum C++ Programming
    Replies: 9
    Last Post: 04-02-2008, 10:26 AM
  3. threads and memory issue
    By Anubhav in forum C Programming
    Replies: 6
    Last Post: 07-25-2006, 04:51 AM
  4. Memory Leak Help
    By (TNT) in forum Windows Programming
    Replies: 3
    Last Post: 06-19-2006, 11:22 AM
  5. Accessing Video Memory Information...need help
    By KneeLess in forum C++ Programming
    Replies: 8
    Last Post: 08-24-2003, 03:53 PM