473,394 Members | 2,063 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Need help with large array memory in C

I need to print an array[256x65536], I made a simple program but alway get error 2 if a=256 and b=65536.
Please help.
.
Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <time.h>
  5. #include <math.h>
  6.  
  7. typedef unsigned int WORD;
  8. typedef WORD* WORDPTR;
  9.  
  10. WORDPTR *S;
  11. WORDPTR  D;
  12.  
  13. WORD x_num;
  14. WORD y_num;
  15.  
  16. WORD a;
  17. WORD b;
  18. WORD i, j;
  19. int main()
  20. {
  21.     puts("------------------ Start --------------------");
  22.     puts("");
  23.  
  24.     a = 0;
  25.     printf("Enter a = ");
  26.     scanf("%u", &a);
  27.  
  28.  
  29.     b = 0;
  30.     printf("Enter b = ");
  31.     scanf("%u", &b);
  32.  
  33.     x_num = 1 << a;
  34.     y_num = 1 << b;
  35.  
  36.     S = (WORDPTR *)malloc(x_num*sizeof(WORDPTR));
  37.     if (S == NULL)
  38.     {
  39.         puts("Error 1!");
  40.         return 1;
  41.     }
  42.     for (i = 0; i < x_num; i++)
  43.     {
  44.     S[i] = (WORDPTR)malloc(y_num*sizeof(WORD));
  45.     if (S[i] == NULL)
  46.     {
  47.         puts("Error 2!");
  48.         return 1;
  49.     }
  50.     }
  51.  
  52.     D = (WORDPTR)malloc(y_num*sizeof(WORD));
  53.     if (D == NULL)
  54.     {
  55.         puts("Error 3!");
  56.         return 1;
  57.     }
  58.     puts("OK!");
  59.  
  60.     return (0);
  61. }
  62.  
Nov 14 '07 #1
1 1059
weaknessforcats
9,208 Expert Mod 8TB
Your code runs OK after compiling with Visual Studio.NET 2005 and executing under Windows XP SP2.
Nov 14 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: [RaZoR] | last post by:
hello, main script creates IE window, put an array there and then calls a child script. chils script makes an array element equal to some object and returns control to main script. then main...
5
by: Crimzon | last post by:
I am using MSVC++ 6.0 compiler. I am declaring an array char ch. Program works fine for these arbitrary sizes. But if I make the size of the array bigger like ch, the program gives me an error...
15
by: MackS | last post by:
The system I am working on supports a subset of C99, among which "standard-compliant VLAs". I've already learnt that VLAs can't have global scope. My question is whether I can safely declare a...
5
by: Michael H | last post by:
Hi all, I guess I don't fully understand how a SHA1 hash value is calculated in C# / .NET for a large file... I'm trying to calculate SHA1 values for large files that are much larger than my...
5
by: apm | last post by:
Any and all: Is there an efficient way to pass a large array from .NET to COM? Can references (or pointer) be passed from COM to NET and NET to COM without the object it refers to being copied?...
6
by: Howard Weiss | last post by:
I am reading a 160 mB file in my application. I want to access the file as shorts. FileStream->Read wants to access the file as Byte so I do the following 1) Read the filesize 2) Create a Byte...
3
by: meltedown | last post by:
Normally, if I use $result=print_r($array,TRUE); print_r prints nothing and $result is equal to the readable array. However, if $array is very large, print_r prints the array and returns...
11
by: Icemokka | last post by:
Hi, I'm need to upload a big file ( 600Mb+ ) to a BLOB field in MSSQL 2005. My code looks like this : fs = New FileStream(sFilePath, FileMode.Open) Dim ByteArray(fs.Length) As Byte...
26
by: Ravindra.B | last post by:
I have declared a global variable which is array of pointers and allocated memory for each array variable by using malloc. Some thing similar to below... static char *arr; main() { int i;
12
by: Nezhate | last post by:
Hi There, I'm writing a program that takes a decimal number and returns it's binary equivalent. the problem is that I don't know how to return (from function) the binary value as an array of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.