10 More Discussions You Might Find Interesting
1. UNIX for Dummies Questions & Answers
I am using ubuntu. I have written a program to calculate prime factors. it works perfectly fine till entered number is less than 9989 (or so ) but when one enters a number higher than that, for example 15000, it does not work. Can anyone guide me whats the problem ? although new codes are welcome,... (2 Replies)
Discussion started by: Abhishek_kumar
2 Replies
2. Programming
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
3. Shell Programming and Scripting
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)
Discussion started by: aarathy
3 Replies
4. Programming
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
5. Programming
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
6. Programming
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
7. Programming
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)
Discussion started by: vigneshinbox
1 Replies
8. Programming
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
9. UNIX for Advanced & Expert Users
Hello!
First of all, forgive me for bad English.
When I starts new thread (pthread_create), system allocates some memory for it (for example, for thread's stack). I wonder when does it deallocate this memory? The problem is that I have a program which sometimes creates new threads and sometimes... (3 Replies)
Discussion started by: prankster
3 Replies
10. UNIX for Dummies Questions & Answers
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
kmem_alloc(9F) Kernel Functions for Drivers kmem_alloc(9F)
NAME
kmem_alloc, kmem_zalloc, kmem_free - allocate kernel memory
SYNOPSIS
#include <sys/types.h>
#include <sys/kmem.h>
void *kmem_alloc(size_t size, int flag);
void *kmem_zalloc(size_t size, int flag);
void kmem_free(void*buf, size_t size);
INTERFACE LEVEL
Architecture independent level 1 (DDI/DKI).
PARAMETERS
size Number of bytes to allocate.
flag Determines whether caller can sleep for memory. Possible flags are KM_SLEEP to allow sleeping until memory is available, or
KM_NOSLEEP to return NULL immediately if memory is not available.
buf Pointer to allocated memory.
DESCRIPTION
The kmem_alloc() function allocates size bytes of kernel memory and returns a pointer to the allocated memory. The allocated memory is at
least double-word aligned, so it can hold any C data structure. No greater alignment can be assumed. flag determines whether the caller can
sleep for memory. KM_SLEEP allocations may sleep but are guaranteed to succeed. KM_NOSLEEP allocations are guaranteed not to sleep but may
fail (return NULL) if no memory is currently available. The initial contents of memory allocated using kmem_alloc() are random garbage.
The kmem_zalloc() function is like kmem_alloc() but returns zero-filled memory.
The kmem_free() function frees previously allocated kernel memory. The buffer address and size must exactly match the original allocation.
Memory cannot be returned piecemeal.
RETURN VALUES
If successful, kmem_alloc() and kmem_zalloc() return a pointer to the allocated memory. If KM_NOSLEEP is set and memory cannot be allocated
without sleeping, kmem_alloc() and kmem_zalloc() return NULL.
CONTEXT
The kmem_alloc() and kmem_zalloc() functions can be called from interrupt context only if the KM_NOSLEEP flag is set. They can be called
from user context with any valid flag. The kmem_free() function can be called from from user, interrupt, or kernel context.
SEE ALSO
copyout(9F), freerbuf(9F), getrbuf(9F)
Writing Device Drivers
WARNINGS
Memory allocated using kmem_alloc() is not paged. Available memory is therefore limited by the total physical memory on the system. It is
also limited by the available kernel virtual address space, which is often the more restrictive constraint on large-memory configurations.
Excessive use of kernel memory is likely to affect overall system performance. Overcommitment of kernel memory will cause the system to
hang or panic.
Misuse of the kernel memory allocator, such as writing past the end of a buffer, using a buffer after freeing it, freeing a buffer twice,
or freeing a null or invalid pointer, will corrupt the kernel heap and may cause the system to corrupt data or panic.
The initial contents of memory allocated using kmem_alloc() are random garbage. This random garbage may include secure kernel data. There-
fore, uninitialized kernel memory should be handled carefully. For example, never copyout(9F) a potentially uninitialized buffer.
NOTES
kmem_alloc(0, flag) always returns NULL. kmem_free(NULL, 0) is legal.
SunOS 5.11 16 Jan 2006 kmem_alloc(9F)