473,396 Members | 1,799 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,396 software developers and data experts.

help with static memory allocation !

I am using MSVC++ 6.0 compiler. I am declaring an array char
ch[5800][20]. Program works fine for these arbitrary sizes. But if I
make the size of the array bigger like ch[10000][20], the program
gives me an error message pertaining to the array size and doesnt
work.
Does it mean that the total size of the array allocated (10000 * 20)
should be less than 65535 or something like that ? The compiler help
file tells that the size of data type character is 1 Byte. Why is
there an issue with the total number of character data types allocated
? System cannot allocate so much bytes contiguously ? Is there a
simple way to overcome this problem using standard data type
declaration, without using malloc or new ? Is it an issue with near /
far pointers ?
System configs are as follows, 512 MB RAM on a INTEL 2405Mhz machine,
OS is WIN XP.
Thanks in advance
Nov 14 '05 #1
5 1988
Crimzon wrote:
I am using MSVC++ 6.0 compiler. I am declaring an array char
ch[5800][20]. Program works fine for these arbitrary sizes. But if I
make the size of the array bigger like ch[10000][20], the program
gives me an error message pertaining to the array size and doesnt
work.
Does it mean that the total size of the array allocated (10000 * 20)
should be less than 65535 or something like that ? The compiler help
file tells that the size of data type character is 1 Byte. Why is
there an issue with the total number of character data types allocated
? System cannot allocate so much bytes contiguously ? Is there a
simple way to overcome this problem using standard data type
declaration, without using malloc or new ? Is it an issue with near /
far pointers ?
System configs are as follows, 512 MB RAM on a INTEL 2405Mhz machine,
OS is WIN XP.
Thanks in advance


This sounds like Question 16.3 in the comp.lang.c
Frequently Asked Questions (FAQ) list

http://www.eskimo.com/~scs/C-faq/top.html

If not, see Question 19.23. If that's still not the
problem, you may have encountered some limitation in
the compiler you're using -- and if that's the case,
seek your answer in an MSVC forum; comp.lang.c won't
have what you need.

--
Er*********@sun.com

Nov 14 '05 #2
Crimzon wrote:

I am using MSVC++ 6.0 compiler. I am declaring an array char
ch[5800][20]. Program works fine for these arbitrary sizes. But if I
make the size of the array bigger like ch[10000][20], the program
gives me an error message pertaining to the array size and doesnt
work.
Does it mean that the total size of the array allocated (10000 * 20)
should be less than 65535 or something like that ? The compiler help
file tells that the size of data type character is 1 Byte. Why is
there an issue with the total number of character data types allocated
? System cannot allocate so much bytes contiguously ? Is there a
simple way to overcome this problem using standard data type
declaration, without using malloc or new ? Is it an issue with near /
far pointers ?
System configs are as follows, 512 MB RAM on a INTEL 2405Mhz machine,
OS is WIN XP.


System specific questions are off-topic here. The C standard
guarantees at most 65536 bytes of storage to be available. The
actual answer probably has something to do with default stack
sizes. You should see a newsgroup dealing with your compiler
and/or OS.

--
Chuck F (cb********@yahoo.com) (cb********@worldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!

Nov 14 '05 #3
kal
cr************@yahoo.com (Crimzon) wrote in message news:<a4**************************@posting.google. com>...

<OT>
I am using MSVC++ 6.0 compiler. I am declaring an array char
ch[5800][20]. Program works fine for these arbitrary sizes. But if I
make the size of the array bigger like ch[10000][20], the program
gives me an error message pertaining to the array size and doesnt
work.
Is it the program that is giving the error message? If so then
looking into the program code should tell you under what conditions
the message is given. One likely cause is erroneous code.
Does it mean that the total size of the array allocated (10000 * 20)
should be less than 65535 or something like that ?
No.

However, you cannot allocate large arrays as local variables (that
is in the stack.) The stack size is usually about 1MB. Such large
aggregates, if necessary, should be allocated with static storage.

On the other hand, it would be better to use dynamic memory
allocation for large storage requirements.
The compiler help
file tells that the size of data type character is 1 Byte. Why is
there an issue with the total number of character data types allocated
? System cannot allocate so much bytes contiguously ? Is there a
simple way to overcome this problem using standard data type
declaration, without using malloc or new ? Is it an issue with near /
far pointers ?
System configs are as follows, 512 MB RAM on a INTEL 2405Mhz machine,
OS is WIN XP.
Thanks in advance


The following works fine in MSVC++ 6.0.

<code>
#include <stdio.h>

int main(int argc, char* argv[])
{
static char ch[1024*1024][64];

ch[0][0] = '1';

ch[1024*1024-1][64-1] = ch[0][0] + 1;

printf("%c, %c\n",ch[0][0],ch[1024*1024-1][64-1]);

return 0;
}
</code>

</OT>
Nov 14 '05 #4
declaration similar to "static char ch[1024*1024][64];" solved the
problem. Though I don't understand at this instance what happens when
the char array is declared static.
Thank you very much !!!

k_*****@yahoo.com (kal) wrote in message news:<a5**************************@posting.google. com>...
cr************@yahoo.com (Crimzon) wrote in message news:<a4**************************@posting.google. com>...

Nov 14 '05 #5
kal
cr************@yahoo.com (Crimzon) wrote in message news:<a4*************************@posting.google.c om>...
declaration similar to "static char ch[1024*1024][64];" solved the
problem. Though I don't understand at this instance what happens when
the char array is declared static.
I don't understand it well either but it works!

The static keyword here indicates that the variable has static
storage duration. That is to say, storage for the variable is
allocated when the program begins and deallocated when the
program ends.

If you will permit me to make a suggestion, if you are going to
do any programming at all using C, then you really ought to get
hold of a copy of that K&R book and read it in its entirety.
Thank you very much !!!


You are most welcome.
Nov 14 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: sks_cpp | last post by:
When do static members allocate memory? (at load time) How about static variables within a method? Where is the memory for static variables - is it allocated on the heap or does it have a...
24
by: Steven T. Hatton | last post by:
In the following code, at what point is S::c fully defined? #include <iostream> using std::cout; using std::endl; using std::ostream; class C { int _v;
11
by: Jonan | last post by:
Hello, For several reasons I want to replace the built-in memory management with some custom built. The mem management itlsef is not subject to my question - it's ok to the point that I have...
83
by: deppy_3 | last post by:
Hi.I am started learning Programm language C before some time.I am trying to make a programm about a very simple "sell shop".This programm hasn't got any compile problem but when i run it i face...
11
by: toton | last post by:
Hi, I have little confusion about static memory allocation & dynamic allocation for a cluss member. I have class like class Bar{ public: explicit Bar(){ cout<<"bar default"<<endl; }
24
by: Ken | last post by:
In C programming, I want to know in what situations we should use static memory allocation instead of dynamic memory allocation. My understanding is that static memory allocation like using array...
6
by: Marvin Barley | last post by:
I have a class that throws exceptions in new initializer, and a static array of objects of this type. When something is wrong in initialization, CGI program crashes miserably. Debugging shows...
9
by: weidongtom | last post by:
Hi, I've written the code that follows, and I use the function add_word(), it seems to work fine *before* increase_arrays() is called that uses realloc() to allocate more memory to words. But...
2
by: Dr Dav | last post by:
Hello all, I'm a physicist whose rewriting a numerical simulation, previously written in IDL, in C with the goal reducing runtime. As you may imagine, my C programming skills are quite poor but I...
10
by: swornavidhya.mahadevan | last post by:
Which allocation (Static / Dynamic) is suitable for the situation when we are trying to allocate for a overloaded memory when the memory is full and no space to allocate. What will happen if both...
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:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.