Can't allocate enough memory for image data

This is a discussion on Can't allocate enough memory for image data within the C Programming forums, part of the General Programming Boards category; I'm receiving this error in my output file: Can't allocate -1124073472 bytes for image data How do I change this ...

  1. #1
    Registered User
    Join Date
    Jul 2006
    Posts
    49

    Question Can't allocate enough memory for image data

    I'm receiving this error in my output file:

    Can't allocate -1124073472 bytes for image data

    How do I change this code to rectify the problem?

    unsigned char *thebuffer = 0;
    thebuffer = malloc(2000000000);

    To effectively answer my question...If any other information/code is needed, then let me know. Thanks

  2. #2
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    You do realize that you're attempting to allocate about 1.8GB of memory, correct? That seems like a bit much, and is probably where your problem is coming from.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >thebuffer = malloc(2000000000);
    You realize that you're trying to allocate just under two gigabytes of data, right? If you honestly need that much data in memory at one time for a simple image, you really need to rethink your design.
    My best code is written with the delete key.

  4. #4
    Registered User
    Join Date
    Mar 2006
    Posts
    725
    Get a bigger RAM chip.
    Code:
    #include <stdio.h>
    
    void J(char*a){int f,i=0,c='1';for(;a[i]!='0';++i)if(i==81){
    puts(a);return;}for(;c<='9';++c){for(f=0;f<9;++f)if(a[i-i%27+i%9
    /3*3+f/3*9+f%3]==c||a[i%9+f*9]==c||a[i-i%9+f]==c)goto e;a[i]=c;J(a);a[i]
    ='0';e:;}}int main(int c,char**v){int t=0;if(c>1){for(;v[1][
    t];++t);if(t==81){J(v[1]);return 0;}}puts("sudoku [0-9]{81}");return 1;}

  5. #5
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,047
    Load a smaller image. Displaying a 2GB image would take a while anyway.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  6. #6
    Registered User
    Join Date
    Jan 2006
    Location
    Berkeley, Ca
    Posts
    195
    On some unnamed operating systems, it's not possible to malloc() more than 2GB of memory. It has something to do with how the userland and kernelland space is divided up in virtual memory. I think there ways to get around this limit.

    If I remember right, the owner of the DNA Lounge had written a program that inserted the date and time into the .jpeg files generated by the clubs web cam. I'm pretty sure it could handle really large honkin files. I say pretty sure because I didn't and still don't have the patience to sit down and read his source code.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Allocate memory inside allocated memory block?
    By Heidi_Nayak in forum C Programming
    Replies: 14
    Last Post: 04-15-2009, 04:19 PM
  2. Memory allocation and deallocation
    By Micko in forum C++ Programming
    Replies: 3
    Last Post: 08-19-2005, 06:45 PM
  3. Binary Tree, couple questions
    By scoobasean in forum C Programming
    Replies: 3
    Last Post: 03-12-2005, 08:09 PM
  4. allocating memory screws up data being read in from file
    By Shadow12345 in forum C++ Programming
    Replies: 5
    Last Post: 12-06-2002, 02:23 PM
  5. gcc problem
    By bjdea1 in forum Linux Programming
    Replies: 13
    Last Post: 04-29-2002, 06:51 PM

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