473,804 Members | 3,349 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2014
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********@yah oo.com) (cb********@wor ldnet.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.go ogle.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.c om (kal) wrote in message news:<a5******* *************** ****@posting.go ogle.com>...
cr************@ yahoo.com (Crimzon) wrote in message news:<a4******* *************** ****@posting.go ogle.com>...

Nov 14 '05 #5
kal
cr************@ yahoo.com (Crimzon) wrote in message news:<a4******* *************** ***@posting.goo gle.com>...
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
8985
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 region of its own?
24
2772
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
912
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 nice and working allocation deallocation routines. However, I don't want to loose the nice extras of new operator, like - constructor calling, typecasting the result, keeping the array size, etc. For another bunch of reasons, outside this scope I...
83
7881
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 some other ploblems which i can not correct.I would appreciated if someone take a look at my programm so as to help me.I tried many times to find out where my mistakes are but i didn't manage something. I have made some comments due to the programm...
11
3063
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
19101
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 is faster than malloc, but dynamic memory allocation is more flexible. Please comment... thanks.
6
3570
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 uncaught exception. How to catch an exception that happened before main() try { ... } catch (...) { ... } block? Is there a way?
9
2520
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 *after* calling increase_arrays(), I received segmentation fault. I tried to step it through gdb, and I found out that after calling increase_arrays(), words's original value is modified, and if I tried to access it, I get <address 0x11 out of...
2
2007
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 am learning. My problem is this. I had sucessfully written a C code that worked ( with considerable speedup over the IDL version ) using an array size of 100x100. However, I am working towards making the array size closer to 300x300. Since I had...
10
4431
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 the allocation is impossible. Sworna vidhya
0
9705
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9576
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10567
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
7613
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6847
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5515
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4291
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3809
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2983
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.