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.
Code:
char* str = (char*)malloc(20*sizeof(char));
str = "This is a string";
But this will also work.
Code:
char* str = "This is a string";
So in which case do we have to allocate memory space?
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)
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)
I have a program that will fetch some particular lines and store it in a buffer for further operations.The code which is given below works but with some errors.I couldn't trace out the error.Can anybody help on this plz??
#include <stdio.h>
#include <stdlib.h>
#include<string.h>
#define... (1 Reply)
I have a scenario like the client has to search for the active server.There will be many servers.But not all server are active.And at a time not more than one server will be active.
The client will be in active state always i.e, it should always search for an active server until it gets one.I... (1 Reply)
i wrote a tiny version of tail command using a large buffer statically allocated but, in a second time, i found another version in which i use a bidimensional array dynamically allocated.
here is the first version
/*my tiny tail, it prints the last 5 line of a file
*/
#include<stdio.h>... (4 Replies)
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)
hello all..
i'm a beginner in shell scripting. I need to know what is really happening when we are creating a variable in shell scripting? how memory is allocated for that variable? (3 Replies)
Hello,
I am new to C++ programming, so I'm still getting a feel for things. I recently wrote a simple C++ program (to be used as a ROOT Macro) to conduct a statistical analysis of a varied version of the Monty Hall problem (code below). Basically, the programs runs a few simple calculations to... (7 Replies)
Discussion started by: Tyler_92
7 Replies
LEARN ABOUT SUNOS
ddi_iopb_free
ddi_iopb_alloc(9F) Kernel Functions for Drivers ddi_iopb_alloc(9F)NAME
ddi_iopb_alloc, ddi_iopb_free - allocate and free non-sequentially accessed memory
SYNOPSIS
#include <sys/ddi.h>
#include <sys/sunddi.h>
int ddi_iopb_alloc(dev_info_t *dip, ddi_dma_lim_t *limits, uint_t length, caddr_t *iopbp);
void ddi_iopb_free(caddr_t iopb);
INTERFACE LEVEL
These interfaces are obsolete. Use ddi_dma_mem_alloc(9F) instead of ddi_iopb_alloc(). Use ddi_dma_mem_free(9F) instead of ddi_iopb_free().
PARAMETERS
ddi_iopb_alloc()
dip A pointer to the device's dev_info structure.
limits A pointer to a DMA limits structure for this device (see ddi_dma_lim_sparc(9S) or ddi_dma_lim_x86(9S)). If this pointer is
NULL, a default set of DMA limits is assumed.
length The length in bytes of the desired allocation.
iopbp A pointer to a caddr_t. On a successful return, *iopbp points to the allocated storage.
ddi_iopb_free()
iopb The iopb returned from a successful call to ddi_iopb_alloc().
DESCRIPTION
ddi_iopb_alloc() allocates memory for DMA transfers and should be used if the device accesses memory in a non-sequential fashion, or if
synchronization steps using ddi_dma_sync(9F) should be as lightweight as possible, due to frequent use on small objects. This type of
access is commonly known as consistent access. The allocation will obey the alignment and padding constraints as specified in the limits
argument and other limits imposed by the system.
Note that you still must use DMA resource allocation functions (see ddi_dma_setup(9F)) to establish DMA resources for the memory allocated
using ddi_iopb_alloc().
In order to make the view of a memory object shared between a CPU and a DMA device consistent, explicit synchronization steps using
ddi_dma_sync(9F) or ddi_dma_free(9F) are still required. The DMA resources will be allocated so that these synchronization steps are as
efficient as possible.
ddi_iopb_free() frees up memory allocated by ddi_iopb_alloc().
RETURN VALUES
ddi_iopb_alloc() returns:
DDI_SUCCESS Memory successfully allocated.
DDI_FAILURE Allocation failed.
CONTEXT
These functions can be called from user or interrupt context.
ATTRIBUTES
See attributes(5) for a description of the following attributes:
+-----------------------------+-----------------------------+
| ATTRIBUTE TYPE | ATTRIBUTE VALUE |
+-----------------------------+-----------------------------+
|Stability Level |Obsolete |
+-----------------------------+-----------------------------+
SEE ALSO attributes(5), ddi_dma_free(9F), ddi_dma_mem_alloc(9F), ddi_dma_mem_free(9F), ddi_dma_setup(9F), ddi_dma_sync(9F), ddi_mem_alloc(9F),
ddi_dma_lim_sparc(9S), ddi_dma_lim_x86(9S), ddi_dma_req(9S)
Writing Device Drivers
NOTES
This function uses scarce system resources. Use it selectively.
SunOS 5.10 27 Sep 2002 ddi_iopb_alloc(9F)