12-09-2009
Quote:
Originally Posted by
macroideal
I mean, I malloc a segment of memory, maybe 1k maybe 20bytes.. assume the pointer is pMem How can I know the content pMem refered is all Zero or \0 . I know memcmp but the second parameter should another memory address... thanx
Never guess or hope. If you want it zeroed, zero it yourself(which is just as fast as checking it). Even if seems to always be zero right now, that may change when you start doing repeated malloc() and free() to the point you get bits of memory you've used before.
9 More Discussions You Might Find Interesting
1. Programming
When run it, segment fault.
What is wrong?
#include <stdio.h>
#include <stdlib.h>
const int max =20;
//****************************************************
// Input Matrix
//****************************************************
void inMatrixAA(int *AA, int row, int col)... (9 Replies)
Discussion started by: zhshqzyc
9 Replies
2. IP Networking
I do have 2 different segment network which different platform on each segment. E.g. 20 segment, Windows OS can talk to Unix OS and 21 segment practice same rule. Further more, Windows OS from 20 segment can talk to 21 segment other OS but only the UNIX OS in 20 segment fail to talk to 21 segment.... (3 Replies)
Discussion started by: HASM
3 Replies
3. Shell Programming and Scripting
Hey all, could someone please direct me on how to extract a segment from a file between two tags? Thanks! (1 Reply)
Discussion started by: mpang_
1 Replies
4. HP-UX
I'm not an HP-UX Admin professional, but rather a Lawson ERP installer. I'm looking for clues on how to troubleshoot this issue. I have WAS 6.1 ND running on HP-UX 11.23 PA-RISC with the Lawson ERP application . When I start the Lawson application, no errors arise. When I start WAS app server, an... (4 Replies)
Discussion started by: mrvitas
4 Replies
5. Shell Programming and Scripting
Hi,
I am using bash. My question concerns cutting out segments of a string. Given the following filename:
S2002254132542.L1A_MLAC.x.hdf
I have been able to successfully separate the string at the periods (.):
$ L1A_FILE=S2002254132542.L1A_MLAC.x.hdf
$ BASE=$(echo $L1A_FILE | awk -F.... (5 Replies)
Discussion started by: msb65
5 Replies
6. UNIX for Dummies Questions & Answers
how do i close a do code segment? od? (1 Reply)
Discussion started by: trob
1 Replies
7. Programming
Hi to all.
I'm reciving a "Segment violation" error from this code and I don't know why.
void insertAtEnd(NodeType *pList) {
char element;
printf("Introduce a element: \n");
setbuf(stdin, NULL);
scanf("%c", &element);
//Find the end of the list;
while... (4 Replies)
Discussion started by: daniel.gbaena
4 Replies
8. Programming
Hi,
Whether the following piece of code is placed in the read-only memory of code (text) segment or data segment?
char *a = "Hello";
I am getting two different answers while searching in google :( that's why the confusion is (7 Replies)
Discussion started by: royalibrahim
7 Replies
9. Programming
I always get segment fault, why? can sb help me and modify it, I have spend on much time on
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#include <string.h>
#define MAX 10
pthread_t thread;
void *thread1()
{
int *a;
int i, n;
... (1 Reply)
Discussion started by: yanglei_fage
1 Replies
LEARN ABOUT LINUX
malloc_get_state
MALLOC_GET_STATE(3) Linux Programmer's Manual MALLOC_GET_STATE(3)
NAME
malloc_get_state, malloc_set_state - record and restore state of malloc implementation
SYNOPSIS
#include <malloc.h>
void* malloc_get_state(void);
int malloc_set_state(void *state);
DESCRIPTION
The malloc_get_state() function records the current state of all malloc(3) internal bookkeeping variables (but not the actual contents of
the heap or the state of malloc_hook(3) functions pointers). The state is recorded in a system-dependent opaque data structure dynamically
allocated via malloc(3), and a pointer to that data structure is returned as the function result. (It is the caller's responsibility to
free(3) this memory.)
The malloc_set_state() function restores the state of all malloc(3) internal bookkeeping variables to the values recorded in the opaque
data structure pointed to by state.
RETURN VALUE
On success, malloc_get_state() returns a pointer to a newly allocated opaque data structure. On error (for example, memory could not be
allocated for the data structure), malloc_get_state() returns NULL.
On success, malloc_set_state() returns 0. If the implementation detects that state does not point to a correctly formed data structure,
malloc_set_state() returns -1. If the implementation detects that the version of the data structure referred to by state is a more recent
version than this implementation knows about, malloc_set_state() returns -2.
CONFORMING TO
These functions are GNU extensions.
NOTES
These functions are useful when using this malloc(3) implementation as part of a shared library, and the heap contents are saved/restored
via some other method. This technique is used by GNU Emacs to implement its "dumping" function.
Hook function pointers are never saved or restored by these functions, with two exceptions: if malloc checking (see mallopt(3)) was in use
when malloc_get_state() was called, then malloc_set_state() resets malloc checking hooks if possible; if malloc checking was not in use in
the recorded state, but the caller has requested malloc checking, then the hooks are reset to 0.
SEE ALSO
malloc(3), mallopt(3)
GNU
2014-06-13 MALLOC_GET_STATE(3)