Sponsored Content
Top Forums Programming dynamic allocation vs static allocation in c Post 302321525 by Corona688 on Monday 1st of June 2009 11:50:24 AM
Old 06-01-2009
What's the difference? Memory is memory.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

memory allocation

I would like to know how I could allocate some more memory to a process. Please note that I am not the root user. (1 Reply)
Discussion started by: sagar
1 Replies

2. Programming

Static variables memory allocation

Hi I want to know when and where memory for static variables are allocated in a C program. If it allocates during compilation will memory be allocated for the variable "i" during compilation itself. int count(); int main(){ printf("%d", count()); return 0; } int count() { ... (8 Replies)
Discussion started by: nathanmca
8 Replies

3. UNIX for Dummies Questions & Answers

HOw to get a variable allocation

HI Gurus, I had a requirement where i want to allocate a file name into a variable and get the file name in the subj of email. Suppose i have a file File002.pdx in the folder /home/pcs/system/files/File002.pdx Iam using a variable a = `ls /home/pcs/system/files/*.pdx` Iam using *... (2 Replies)
Discussion started by: pssandeep
2 Replies

4. Programming

Dynamic memory allocation

Hi, I am trying to process line by line of a file. But I should not be allocating static allocation for reading the contents of the file. The memory should be dynamically allocated. The confusion here is how do I determine the size of each line, put it into a buffer with the memory allocated... (11 Replies)
Discussion started by: naan
11 Replies

5. Programming

array dynamic allocation

Hi, I have the following problem: i must allocate a dynamic array from a subroutine which should return such array to main function. The subroutine has already a return parameter so i thought of pass the array as I/O parameter. I tried the following program but it doesn't work (segmentation... (11 Replies)
Discussion started by: littleboyblu
11 Replies

6. Programming

global variables and dynamic allocation

Hi, is it possible in C to allocate dynamically a global variable?? (3 Replies)
Discussion started by: littleboyblu
3 Replies

7. Programming

Memory allocation in C

Hi Experts I need some help in static memory allocation in C. I have a program in which I declared 2 variables, one char array and one integer. I was little surprised to see the addresses of the variables. First: int x; char a; printf("%u %u\n', &x, a); I got the addresses displayed... (2 Replies)
Discussion started by: unx_freak
2 Replies

8. Programming

Dynamic Memory Allocation

Hello Guys I have a small confusion in the dynamic memory allocation concept. If we declare a pointer say a char pointer, we need to allocate adequate memory space. char* str = (char*)malloc(20*sizeof(char)); str = "This is a string"; But this will also work. char* str = "This... (2 Replies)
Discussion started by: tene
2 Replies

9. Solaris

Block-based allocation and Extent-based allocation in Solaris

Hi guys! Could you tell me what's this figure about? (See the attached figure below.) This is a representation of block allocation filesystem and extent allocation filesystem in Solaris. Does this mean that in a block-based allocation, data are placed in individual blocks while in... (0 Replies)
Discussion started by: arah
0 Replies

10. Programming

Memory Allocation Query

When we dynamically allocate the memory say 100 integers say int *x = new int(1000); then does entire chunk of memory gets allocated at once after the completion of the statement? I mean will the the concept of page fault come into picture over here? (3 Replies)
Discussion started by: rupeshkp728
3 Replies
contig_malloc(9r)														 contig_malloc(9r)

NAME
contig_malloc - General: Allocates physically contiguous memory SYNOPSIS
#include <sys/malloc.h> void * contig_malloc( u_long size, u_long alignment, u_long addrlimit, int type, int flag ); ARGUMENTS
Specifies the size of the memory (in bytes) to allocate. Specifies the alignment of the memory to be allocated. For example, for a 256-byte alignment, you should pass the value 256. A 0 (zero) value means there is no alignment requirement. Specifies that the address of all the allocated memory should be less than or equal to this address. A 0 (zero) value means that there is no address limit requirement. Specifies the purpose for which the memory is being allocated (or freed). The memory type constants are defined in the file /usr/sys/include/sys/malloc.h. Examples of memory type constants are M_DEVBUF (device driver memory), M_KTABLE (kernel table memory), M_RTABLE (routing tables memory), and so forth. Specifies one of the following flags defined in /usr/sys/include/sys/malloc.h: Signifies that contig_malloc should zero the allocated memory. Signifies that contig_malloc can block. Signifies that contig_malloc cannot block. DESCRIPTION
The contig_malloc routine allocates physically contiguous memory during the boot process (before single-user mode). The routine carves out an area of physically contiguous memory from a contiguous memory buffer and allocates memory from this buffer with proper alignment. The call to contig_malloc is the same for statically or dynamically configured drivers. However, the point or points in time in which the stat- ically or dynamically configured driver requests the memory differ. A statically configured driver typically needs to call contig_malloc only before single-user mode. In this case, contig_malloc obtains the memory from the contiguous memory buffer. When a statically configured driver frees this physically contiguous memory (by calling the con- tig_free routine), the memory is returned to the virtual memory subsystem. A dynamically configured driver typically needs physically contiguous memory after single-user mode. As stated previously, contig_malloc carves out an area of physically contiguous memory from a contiguous memory buffer before single-user mode. Thus, this memory would not be available to the dynamically configured driver after single-user mode. To solve this problem, a dynamically configured driver calls con- tig_malloc by defining the CMA_Option attribute in the sysconfigtab file fragment. The cma_dd subsystem calls contig_malloc on behalf of dynamically configured device drivers and obtains the memory allocation size (and other information) from the CMA_Option attribute field. In this case, contig_malloc allocates physically contiguous memory from the con- tiguous memory buffer and places it in a saved memory pool. When a dynamically configured driver needs to call contig_malloc after single- user mode, the physically contiguous memory comes from this saved memory pool. When a dynamically configured driver frees this physically contiguous memory (by calling the contig_free routine), the memory is returned to the saved memory pool (not to the virtual memory subsys- tem). Thus, this physically contiguous memory is available to the dynamically configured driver upon subsequent reload requests that occur after single-user mode. RETURN VALUES
Upon successful completion, contig_malloc returns a pointer to the allocated memory. If contig_malloc cannot allocate the requested memory, it returns a null pointer. SEE ALSO
Routines: contig_free(9r) contig_malloc(9r)
All times are GMT -4. The time now is 06:15 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy