+ Post New Thread
Page 1 of 2 1 2 LastLast
Results 1 to 20 of 29
  1. #1
    Advanced Member level 3
    Points: 8,212, Level: 21

    Join Date
    Jan 2004
    Location
    USA
    Posts
    864
    Helped
    94 / 94
    Points
    8,212
    Level
    21

    createimage devc++ -java

    Hi,
    I am using malloc to dynamically resize 2-D integer array for image processing. But whenever I try to resize the array for values more than 15kb (120x120) memory allocation fails and thus I am not able to process any image greater than 120 x 120 pixels. I am using Turbo C 3.0 operating in DOS Shell from windows.
    Is this the maximum memory that can be assigned for a 2-D array? How can I increase it further?

  2. #2
    Full Member level 4
    Points: 4,651, Level: 16

    Join Date
    Nov 2001
    Posts
    236
    Helped
    9 / 9
    Points
    4,651
    Level
    16

    Malloc allocation fails!

    Strange...
    Can you place a sample code ilustrating....

    NeuralC



  3. #3
    Junior Member level 2
    Points: 1,836, Level: 9

    Join Date
    Dec 2002
    Posts
    20
    Helped
    1 / 1
    Points
    1,836
    Level
    9

    Re: Malloc allocation fails!

    What is the memory model that you use?
    Tiny,Large,hughe...



    •   AltAdvertisement

        
       

  4. #4
    Advanced Member level 3
    Points: 8,212, Level: 21

    Join Date
    Jan 2004
    Location
    USA
    Posts
    864
    Helped
    94 / 94
    Points
    8,212
    Level
    21

    Re: Malloc allocation fails!

    Quote Originally Posted by neuralc
    Strange...
    Can you place a sample code ilustrating....
    NeuralC
    This is my code
    Code:
    void CreateImage(int ***image, int& M, int& N)
    {
    
    	int i,j;
    	if((*image=(int **)malloc(N*sizeof(int *)))==NULL)
    	{
    		cout<< "Not enough memory!";
    		getch();
    		exit(0);
    	}
    
    	for(i=0;i<N;i++)
    	{
    		if(((*image)[i]=(int*)malloc(M*sizeof(int)))==NULL)
    		{
    			cout<< "Not enough memory!";
    			getch();
    			exit(0);
    		}
    	}
    Quote Originally Posted by proiettile
    What is the memory model that you use?
    Tiny,Large,hughe...
    Memory model is small.



  5. #5
    Advanced Member level 5
    Points: 32,456, Level: 44

    Join Date
    Apr 2002
    Location
    USA
    Posts
    3,942
    Helped
    663 / 663
    Points
    32,456
    Level
    44

    Malloc allocation fails!

    How big is your compiler's int? 2 or 4 bytes?

    Small model probably gives you only 64K of data space. Your second loop allocates N*M*sizeof(int) bytes. That plus whatever the compiler has already consumed probably exceeds 64K. Try a different memory model.



  6. #6
    Advanced Member level 3
    Points: 8,212, Level: 21

    Join Date
    Jan 2004
    Location
    USA
    Posts
    864
    Helped
    94 / 94
    Points
    8,212
    Level
    21

    Re: Malloc allocation fails!

    I tried it with HUGE model but still there is no change. I even changed the pointers to "far" and used farmalloc instead of malloc. Still allocation falis for large images! :(



  7. #7
    Full Member level 4
    Points: 4,651, Level: 16

    Join Date
    Nov 2001
    Posts
    236
    Helped
    9 / 9
    Points
    4,651
    Level
    16

    Malloc allocation fails!

    try this:

    int **CreateImage(int M, int N)
    {
    int i;
    int **pt;
    if((pt=malloc(N*sizeof(int *)))==NULL)
    {
    cout<< "Not enough memory!";
    getch();
    exit(0);
    }

    for(i=0;i<N;i++)
    {
    if((pt[i]=malloc(M*sizeof(int)))==NULL)
    {
    cout<< "Not enough memory!";
    getch();
    exit(0);
    }
    }
    return pt;
    }

    With MS compiler I have tryed to build an array of 1200*1200 sucessfully:
    void main(void){

    int **myImage=NULL;
    myImage=CreateImage(1200,1200);
    }


    HH

    NeuralC



  8. #8
    Advanced Member level 4
    Points: 12,348, Level: 26
    artem's Avatar
    Join Date
    May 2003
    Location
    Turkey
    Posts
    1,350
    Helped
    128 / 128
    Points
    12,348
    Level
    26

    Malloc allocation fails!

    There is a link how set heap and stack size but for Borland 4.5 . If TC3 does nto support that , may be you can chnage to 4.5 version
    http://teaching.idallen.com/c_progra...TimeStack.html

    May be wrong handling different memory model versions is subject to blame in TC3 .
    Check the borland site - there could be hints

    P.S. Allocating memory for pointers is good to have faster access , but you will use extra 1200 * sizeof(int*) memory . You know array geometry apriori so it is redundant to have additional pointer array .



  9. #9
    Full Member level 2
    Points: 2,549, Level: 11
    Pinczakko's Avatar
    Join Date
    Jul 2004
    Location
    Taka Bonerate National Park, Indonesia
    Posts
    138
    Helped
    13 / 13
    Points
    2,549
    Level
    11

    Re: Malloc allocation fails!

    if you don't have any problem to switch to another compiler, it's better to use Microsoft Visual C++ and using the "real" memory allocation routine within the OS itself (win32API), I think it's faster. The Win32API functions are :
    1. VirtualAlloc
    2. HeapAlloc
    3. GlobalAlloc
    4. LocalAlloc
    IIRC one of this function is called from the malloc library function within the OS itself. What I mean by this, is the malloc function call will be resolved by the "dynamic linking process" into one of the function above.



    •   AltAdvertisement

        
       

  10. #10
    Advanced Member level 3
    Points: 8,212, Level: 21

    Join Date
    Jan 2004
    Location
    USA
    Posts
    864
    Helped
    94 / 94
    Points
    8,212
    Level
    21

    Re: Malloc allocation fails!

    Hi,
    The problem is solved now. The compiler was giving problem with farmalloc. If I try to execute my program when compiler is running, it was giving trouble. Running the compiled .exe after closing the compiler IDE works witout problems.



    •   AltAdvertisement

        
       

  11. #11
    Advanced Member level 5
    Points: 32,456, Level: 44

    Join Date
    Apr 2002
    Location
    USA
    Posts
    3,942
    Helped
    663 / 663
    Points
    32,456
    Level
    44

    Malloc allocation fails!

    That memory model stuff is pure agony. How about switching to a newer compiler? Decades ago I used Borland DOS tools, but then I discovered djgpp and later mingw. I've been smiling ever since. Both are free.
    http://www.delorie.com/djgpp/ (gcc for DOS)
    http://www.mingw.org/ (gcc for Windows)



  12. #12
    Advanced Member level 3
    Points: 8,212, Level: 21

    Join Date
    Jan 2004
    Location
    USA
    Posts
    864
    Helped
    94 / 94
    Points
    8,212
    Level
    21

    Re: Malloc allocation fails!

    Hi,
    What is your opinion on Bloodshed Dev C++?



  13. #13
    Member level 5
    Points: 1,968, Level: 10

    Join Date
    Jul 2004
    Posts
    94
    Helped
    0 / 0
    Points
    1,968
    Level
    10

    Re: Malloc allocation fails!

    hi, what is "getch()"? i have problem compiling the codes above. it says undeclared identifier.

    Do i need a header or something?

    Thanks!



  14. #14
    Advanced Member level 3
    Points: 8,212, Level: 21

    Join Date
    Jan 2004
    Location
    USA
    Posts
    864
    Helped
    94 / 94
    Points
    8,212
    Level
    21

    Re: Malloc allocation fails!

    getch() will wait until user presses any key. It actiually returns ascii value of the key. It is defined in "conio.h" For c++ use cin;



  15. #15
    Member level 5
    Points: 1,968, Level: 10

    Join Date
    Jul 2004
    Posts
    94
    Helped
    0 / 0
    Points
    1,968
    Level
    10

    Re: Malloc allocation fails!

    got it! but i have problems with the exit() now..nieway,i'll figure it out myself..thanks again!!

    btw, CMOS, isnt this array thingy u're doing related to mine? remember? I asked u about the threshold stuffs



  16. #16
    Advanced Member level 3
    Points: 8,212, Level: 21

    Join Date
    Jan 2004
    Location
    USA
    Posts
    864
    Helped
    94 / 94
    Points
    8,212
    Level
    21

    Re: Malloc allocation fails!

    Quote Originally Posted by zkai2000
    btw, CMOS, isnt this array thingy u're doing related to mine? remember? I asked u about the threshold stuffs
    Yes it is related to 2D arrays for image processing.



    •   AltAdvertisement

        
       

  17. #17
    Member level 5
    Points: 1,968, Level: 10

    Join Date
    Jul 2004
    Posts
    94
    Helped
    0 / 0
    Points
    1,968
    Level
    10

    Re: Malloc allocation fails!

    r u going to express it using GUI?

    if im gonna use VB as GUI, i'll have to save the c++ codes into a dll file. then use VB to read it rite?



  18. #18
    Full Member level 2
    Points: 2,549, Level: 11
    Pinczakko's Avatar
    Join Date
    Jul 2004
    Location
    Taka Bonerate National Park, Indonesia
    Posts
    138
    Helped
    13 / 13
    Points
    2,549
    Level
    11

    Re: Malloc allocation fails!

    Quote Originally Posted by zkai2000
    if im gonna use VB as GUI, i'll have to save the c++ codes into a dll file. then use VB to read it rite?
    Of course that's the path to take if you will use VB as the GUI. I've done thing like this before, but I'm interfacing VB to a dll which is built using C language, not C++.



  19. #19
    Advanced Member level 3
    Points: 8,212, Level: 21

    Join Date
    Jan 2004
    Location
    USA
    Posts
    864
    Helped
    94 / 94
    Points
    8,212
    Level
    21

    Re: Malloc allocation fails!

    Thats one and faster way of doing it. Or you can write same code in VB too.



  20. #20
    Member level 5
    Points: 1,968, Level: 10

    Join Date
    Jul 2004
    Posts
    94
    Helped
    0 / 0
    Points
    1,968
    Level
    10

    Re: Malloc allocation fails!

    nope i cant..coz i need C++ to do my change of orientations algorithm. i need to swing the array map around :D
    AFAIK, VB cant do that rite? :(



--[[ ]]--