473,406 Members | 2,867 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,406 software developers and data experts.

1 K or 1 G Array

Hello!

I am running some tests and I need to create arrays of specific sizes. I have scavenged many online tutorials/materials to try to find out how I can generate a 1-kilobyte or a 1-gigabyte array in C (or python) without much success.

Could anyone please help?

Gratefully yours,

atwinix
Jan 5 '10 #1
5 2181
alexis4
113 100+
1K is 1000000 times smaller than 1G!!!
Anyway, what exactly are you missing and need help for? I have never tried to create such big arrays before, but is it programmatically different to create a 1K array and a 10byte array?
Jan 5 '10 #2
myusernotyours
188 100+
The size of char on most systems is generally 1 byte long. One KB = 1024 bytes, so a declaration such as
Expand|Select|Wrap|Line Numbers
  1.  char kb[1024]; 
is exactly one kilobyte long.

You could do something similar for a GB but you have to be careful about where the memory comes from.
Local variables will be allocated on the part of memory known as the Stack which is considerably limited on most systems so you could get errors like Stack Overflow if you allocate a very huge local array.

If you want a GB array you should use the Heap which is bigger. You use the malloc() function to allocate memory on the Heap.

Kind Regards,

Alex.
Jan 5 '10 #3
Banfa
9,065 Expert Mod 8TB
The size of char on most systems is generally 1 byte long.
More precisely the size of char on all systems is defined by the standard as being 1 byte long. What is variable is the number of bits in that byte.
Jan 5 '10 #4
myusernotyours
188 100+
More precisely the size of char on all systems is defined by the standard as being 1 byte long. What is variable is the number of bits in that byte.
Thankyou for that enlightment. :)
Jan 5 '10 #5
Thanks for the replies! I actually did something similar. I created char 1k[1024]. But I just wanted to confirm if there was actually any harm in doing so, especially when doing the same for the 1G array. Or if there was a better way of doing it.

I am mostly a Python/Java programmer. I just got started with C in my internship and I am trying to see if larger arrays will cause memory modules to consume more power. I have to run the c program on the most minimalist linux kernel - enough to compile the c program. The computer I am using is very new and has more than ample memory to hold a 1G array.

Your input have been very helpful. I shall check malloc() as well to get a better understanding.

Thanks a lot for all the help.
Jan 5 '10 #6

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

Similar topics

2
by: Brian | last post by:
I'm diddlying with a script, and found some behavior I don't understand. Take this snippet: for ($i = 0; $i <= count($m); $i++) { array_shift($m); reset($m); }
2
by: Stormkid | last post by:
Hi Group I'm trying to figure out a way that I can take two (two dimensional) arrays and avShed and shed, and subtract the matching elements in shed from avShed I've pasted the arrays blow from a...
15
by: lawrence | last post by:
I wanted to test xml_parse_into_struct() so I took the example off of www.php.net and put this code up on a site: <?php $simple = <<<END <item>
8
by: vcardillo | last post by:
Hello all, Okay, I am having some troubles. What I am doing here is dealing with an employee hierarchy that is stored in an array. It looks like this: $employees = array( "user_id" => array(...
12
by: Sam Collett | last post by:
How do I remove an item with a specified value from an array? i.e. array values 1,2,2,5,7,12,15,21 remove 2 from array would return 1,5,7,12,15,21 (12 and 21 are NOT removed, duplicates are...
8
by: Mike S. Nowostawsky | last post by:
I tried using the "toUpperCase()" property to change the value of an array entity to uppercase BUT it tells me that the property is invalid. It seems that an array is not considered an object when...
58
by: jr | last post by:
Sorry for this very dumb question, but I've clearly got a long way to go! Can someone please help me pass an array into a function. Here's a starting point. void TheMainFunc() { // Body of...
104
by: Leszek | last post by:
Hi. Is it possible in javascript to operate on an array without knowing how mamy elements it has? What i want to do is sending an array to a script, and this script should add all values from...
7
by: Jim Carlock | last post by:
Looking for suggestions on how to handle bad words that might get passed in through $_GET variables. My first thoughts included using str_replace() to strip out such content, but then one ends...
17
by: =?Utf-8?B?U2hhcm9u?= | last post by:
Hi Gurus, I need to transfer a jagged array of byte by reference to unmanaged function, The unmanaged code should changed the values of the array, and when the unmanaged function returns I need...
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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,...
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
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
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.