answersLogoWhite

0


Best Answer

The easy way to create a large array is to define it however big you want, and then use a compiler and operating system that can handle that size.

int length_test(void){

int stuff[99000] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 4};

stuff[4] = 7;

return stuff[4];

}

For this purpose there are two functions which may depend on the platform you you use , These both function increase and change your DATA SEGMENT and BREAK VALUE These are: 1. brk() 2. sbrk() Please use them. If feel unconfident write to me on: rupesh_joshi@sify.com rupesh.joshi@gmail.com

Many compilers for embedded systems limit the stack space used by any one function (including all the local arrays defined in that function) to 64 KB or sometimes 4 KB.

Such compilers often treat local arrays, global arrays, constant arrays, and heap arrays differently. So sometimes, if you can change the program so the array is a different kind of array, you can make it much bigger. So if the above code is "too big", perhaps the following code will compile:

int stuff[99000] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 4};

int length_test(void){

stuff[4] = 7;

return stuff[4];

}

See the question "Write a C program to reverse the first n characters in a file?" for some tips on writing to a file.

User Avatar

Wiki User

8y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you create an array for a memory block greater than 64Kb and store that array in a file?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What is Arrays of Pointers?

An array of pointers is a contiguous block of memory that contains pointers to other memory locations. They essentially allow non-contiguous memory locations to be treated as if they were an actual array.


How do you represent a one dimensional array in memory?

A one-dimensional array is always represented as a single contiguous block of memory. The size of the allocation is determined by the array's type and the number of elements of that type. For instance, if you create an array of 10 elements where each element is 4 bytes in length, the total allocation will be 40 bytes. The array name is a reference to the start of the allocation and individual elements are accessed via an indexed offset from this reference, such that the first element is at offset 0, the next is at offset 1, and so on.


What are the different between array and variables?

A variable is a reference to a single object (often a number, character, or string of characters). An array is a reference to a contiguous block of memory in which zero or more individual objects.


What is array in C languange?

An array is a contiguous block of data in memory. When you declare an array in C you need to give it a type and a name (like a normal variable), plus you need to give it a size. // normal integer variable x int x; // array of 10 integers int x[10]; Remember that the variable x is actually just a pointer, or reference, to a point in memory. This point in memory is the start of the array, so the value at x[0] is the first value in the array, x[1] is the second, and so on. Also remember that C has no bounds checking, so you can, indeed, read any value past the maximum. x[3474] would return an integer value, but it's going to be some part of memory that is not in your array. Attempting to change this value could result in something very bad happening.


What is the difference between a pointer and an array in C programming?

An array is a contiguous block of memory containing one or more elements of the same type. The array identifier is a reference to that block of memory. References do not require any memory other than the memory they reference. References are not variables -- they are merely aliases for memory addresses. A pointer is a variable that can store any reference and provides indirect access to that reference. Pointers can be used to allocate arrays dynamically, which means memory is required not only for the array, but also for the pointer to store the starting memory address of the array. Once allocated, the array can be referenced directly, but the pointer is still required in order to release the memory allocation when it is no longer required. Arrays employ pointer arithmetic to locate individual elements by their zero-based index, which is essentially an offset from the reference multiplied by the size of the element type. However arrays and pointers are not the same from a programming standpoint. Your compiler may well implement references as pointers, but that is only of concern to compiler authors, not programmers. Two-dimensional dynamic arrays make use of a pointer-to-pointer variable to point to a one-dimensional array of pointers, each of which points to a one-dimensional array of the actual elements. A three-dimensional array employs a pointer-to-pointer-to-pointer to point to a one-dimensional array of pointer-to-pointer variables, each of which points to a two-dimensional array. And so on. Static arrays use less memory as there is no need to maintain arrays of pointers, but static arrays are only useful when the number of elements and dimensions are known at compile time. At runtime, arrays of pointers are required over and above the array elements themselves, in order to both allocate and deallocate the memory, as well as obtain references to the elements in the array. Pointers also have uses beyond that of dynamic arrays, including allocating any type of memory of any size, and pointing at functions which can then be passed as arguments to other functions.


What is integer type array?

An array is a collection of similar data types. An integer array is nothing but a collection of integer data types. Ex: int a[100], int arr[100][100] There are several types. 1D array, 2D array, Multi-Dimensional array. But array is a contiguous allocation. And array size will always be positive. It can be given in the declaration stage or we can specify it dynamically by using malloc function. Ex: int *a; a=(int*)malloc(sizeof(int)*HOW_MANY_NUMBERS_YOU_WANT);


Differentiate pointer and arrays in point?

A pointer is simply a primitive variable, not unlike an int. Its length (in bits) is determined by the underlying architecture: typically 32 bits on a 32-bit system or 64 bits on a 64-bit system. Just as an int variable stores a numeric value in memory, a pointer stores a memory address in memory. The pointer is said to "point at" that address, and can be dereferenced to indirectly access the actual value stored at that address (known as indirection). A pointer can point to a memory address containing another pointer, adding another level of indirection. An array is simply a contiguous block of memory divided into one or more elements. The array name is a reference to the start address of that block, which is also the address of the first element in the array. Just as an array can contain one or more int types, an array can also contain one or more pointer types. This is typically used in C-style dynamic multi-dimensional arrays, where each pointer points to the start address of another array. Unlike static multi-dimensional arrays which are allocated in a single block for all dimensions, arrays of pointers can point to arrays stored anywhere on the heap. This makes it possible to store enormous arrays non-contiguously (each array being pointed at is itself contiguous but the array as a whole is non-contiguous).


Can you simulate linked list using arrays?

I would say no, but it really depends on your point of view. An array and a linked list can both hold the same data; the only difference is how they do so. The definition of a linked list is a sequence of connected nodes. An array is a contiguous block of memory, so you can think of an array as a linked list in which each element is spacially connected to the next.


What do you mean by array with examples?

An array is any contiguous block of allocated memory that contains one or more instances of the same data type, where each instance (known as an element) is accessible independently of the others via the element's unique index (calculated as a zero-based offset from the start of the array).Arrays are typically one-dimensional (a string of characters is an example of a one-dimensional array) but they can be multi-dimensional. This allows data to be conceptualised as a rectangular grid, with rows and columns (a two-dimensional array), or as a cuboid (a three-dimensional array).Going beyond three-dimensions is difficult to imagine in a 3D world, however a four-dimensional array can be likened to a cuboid where each element in the cuboid contains a one-dimensional array. A six-dimensional array is therefore a cuboid where each element contains a cuboid, and so on.Arrays can be static or dynamic. Static arrays are those where the dimensions are known at compile time and are allocated on the stack. Dynamic arrays are dimensioned at runtime and allocated on the heap.The following are examples of static arrays:char x[10]; // Allocates memory for 10 characters.int sudoku[9][9]; // Allocates memory for 81 integers (9x9).int rubik[3][3][3]; Allocates memory for 27 integers (3x3x3).It's important to remember that dimension indices are zero-based, because they represent memory offsets from the beginning of the array. Therefore the first element of array x is x[0], and the last is x[9]. x itself is an alias to the block of memory allocated to the array named x, and is therefore the same as the address occupied by element x[0].Offsets are calculated by the size of the data in each element, thus x[1] can be found at the address 1*sizeof(char) bytes from the address of x. In multi-dimensional arrays, the offsets are calculated by multiplying the dimensions. Thus rubik[2][0][1] will be found ((2*9)+(0*3)+1)*sizeof(int) bytes from the address of rubik.Dynamic arrays are created by maintaining a pointer to the start of the array. Thus:int * pArray=new int[10]; // Allocates memory to 10 integers on the free store.The value stored in the variable pArray is therefore the start address of the array, the same address occupied by pArray[0].The memory can be released with a call to delete:delete[] pArray;Note the use of [] to indicate that the entire array is to be deleted. If we don't do this, only the first element would be released, causing a memory leak.Multi-dimensional dynamic arrays are a bit trickier to deal with as each dimension adds an extra level of indirection and the array itself is not guaranteed to reside in contiguous memory. In fact, it's easier to think of them as being separate one-dimensional arrays, each with their own pointer, and those pointers residing in their own separate array.However, it's still possible to allocate multi-dimensional arrays in contiguous memory by allocating the memory as a single block, rather than allocating each dimension independently. A separate array of pointers are used to divide the block however you see fit. For instance, to allocate a 5x6 dynamic array of type int, you'd use the following:int ** pp = new int*[5]; // allocate pointer arraypp[0] = new int[5*6]; // allocate the contiguous blockfor(int i=1;i


If any array has seven rows how many blocks does it have?

Define 'block'. If 'block' means 'row' then seven.


The elements in an array must be of the same basic data type but why must they be stored in contiguous memory?

An array is nothing more than a block of contiguous memory addresses divided into one or more units of equal length. We call these units elements. As a result, all elements of an array must be allocated contiguously. Other than padding for memory alignment purposes, an array offers the most compact storage for multiple elements of the same type. And because the elements are allocated contiguously, it is trivial to traverse the array from one element to the next using nothing more than a pointer variable of the same type as the array. Each increment or decrement of the pointer increases or decreases the address by 1 element. The array suffix operator [] does the same thing, except the index is a zero-based offset from the start of the array. The first element is index 0 because it is 0 elements from the start of the array while the nth element is found at index n-1. When we create an array we have the choice of storing the objects themselves in the array or storing a pointer to the objects. With the latter, the objects need not be allocated contiguously, however we consume more memory because the array of pointers consumes additional memory that we wouldn't need to consume were all the objects allocated in the array itself. We also have the additional cost of dereferencing those pointers in order to access the objects being referred to. However, arrays of pointers are advantageous when the objects are larger than a pointer (in bytes) or are of polymorphic type. Copying or moving a large object in memory is more expensive than copying or moving a pointer, so if we need to sort an array of large objects, an array of pointers is generally more efficient despite the indirection. But with polymorphic types we have to use pointers because polymorphic types are not guaranteed to be the same length so we must store a pointer to the common base type if we wish to retain polymorphic behaviour.


Spark plug wires array in a big block Chevy?

1,8,4,3,6,5,7,2.