Все вопросы: [malloc]

132 вопросов

похожие теги: malloc-history
0
голосов
1ответов
635 просмотров

Malloc/free algorithm in Suse

Which implementation of malloc/free is used in a specific Linux distribution (in my case Suse 9 and Suse 10) ? Has it change between both versions ? Is it the same algorithm for 32 bits and 64 bits versions ?

7
голосов
10ответов
27869 просмотров

Can you define the size of an array at runtime in C

New to C, thanks a lot for help. Is it possible to define an array in C without either specifying its size or initializing it. For example, can I prompt a user to enter numbers and store them in an int array ? I won't know how many numbers they will enter beforehand. The only way I can think ...

0
голосов
2ответов
561 просмотров

The C# compiler and memory management

I'm doing a compiler design class on the topic of memory management. I am reading about garbage collection and noticed that most of that low level stuff takes place with C/C++ code. I have a few questions about the c# compiler. Was .net framework part for memory management written in c/c++? How...

1
голосов
7ответов
8253 просмотров

malloc code in C

I have a code block that seems to be the code behind malloc. But as I go through the code, I get the feeling that parts of the code are missing. Does anyone know if there is a part of the function that's missing? Does malloc always combine adjacent chunks together? int heap[10000]; void* malloc...

0
голосов
4ответов
3504 просмотров

Using strtok() on an allocated string?

Is there anything I should know about using strtok on a malloced string? In my code I have (in general terms) char* line=getline(); Parse(dest,line); free(line); where getline() is a function that returns a char * to some malloced memory. and Parse(dest, line) is a function that does parsing ...

1
голосов
2ответов
349 просмотров

Divide large malloc-block into smaller "partitions"

Is there a way to use poiter arithmetic on a large malloc block, so you can assign multiple structs or primitive data types to that area already allocated? I'm writing something like this but it isnt working (trying to assign 200 structs to a 15000byte malloc area): char *primDataPtr = NULL; t...

2
голосов
6ответов
3409 просмотров

strange malloc behavior in C

I am trying to create a matrix with dynamic proportions and to initialize it here is the code I am using to allocate memory and initialization: int **matrix; //mem allocation matrix=(int*)malloc(sizeof(int*)*mat_w); for (i=0;i<mat_w;i++) matrix[i]=(int)malloc(sizeof(int)*mat_h); //init fo...

8
голосов
2ответов
7410 просмотров

tcmalloc: how can I get my malloc calls overridden when compiling statically?

When I use LD_PRELOAD=/usr/local/lib/libtcmalloc.so, all my calls to malloc become tcmalloc calls. However, when I link statically against libtcmalloc, I find that straight malloc is getting called unless I still use the LD_PRELOAD setting. So how can I statically compile against tcmalloc in su...

0
голосов
2ответов
237 просмотров

I have a dynamic library, how to know if it calls malloc during run-time?

I need to do networking in uCsimm, Motorola Dragon Ball. As I'm running uClinux with RTAI patch, and I need real-time performance, therefore all malloc and its friends are undesirable. I have the following piece of code for socket dynamic library. How to know that it calls malloc during run-time?...

1
голосов
3ответов
518 просмотров

Problems with 'Heap Buffer' Error in C

I get the following error in my C program: Writing to heap after end of help buffer Can you tell me what I'm missing? char * path_delimiter(char * path) { int i = 0, index = 0, size = 0, length = (int)strlen(path); char *tmp, *ans; for(; i < length; i++) { if(path[i]...

788
голосов
14ответов
536269 просмотров

Difference between malloc and calloc?

What is the difference between doing: ptr = (char **) malloc (MAXELEMS * sizeof(char *)); or: ptr = (char **) calloc (MAXELEMS, sizeof(char*)); When is it a good idea to use calloc over malloc or vice versa?

7
голосов
3ответов
813 просмотров

Potential problem with C standard malloc'ing chars

When answering a comment to another answer of mine here, I found what I think may be a hole in the C standard (c1x, I haven't checked the earlier ones and yes, I know it's incredibly unlikely that I alone among all the planet's inhabitants have found a bug in the standard). Information follows: ...

10
голосов
8ответов
7363 просмотров

newbie questions about malloc and sizeof

Can someone explain to me why my call to malloc with a string size of 6 returns a sizeof of 4 bytes? In fact, any integer argument I give malloc I get a sizeof of 4. Next, I am trying to copy two strings. Why is my ouput of the copied string (NULL)? Following is my code: int main() { char * ...

0
голосов
4ответов
287 просмотров

C can someone tell me what is going on here?

I can not figure out what the heck is happening here. What I expect is that the output should say that there is only 1 element in keys, it's saying there are 7 when I have allocated only the 0 position with 120 bytes. void add2(char **b, char *i) { if (!i) { b[0] = (char*) malloc(120...

5
голосов
4ответов
18802 просмотров

strtok and memory leaks

I wrote a simple url parser using strtok(). here's the code #include <stdio.h> #include <stdlib.h> typedef struct { char *protocol; char *host; int port; char *path; } aUrl; void parse_url(char *url, aUrl *ret) { printf("Parsing %s\n", url); char *tmp = (c...

0
голосов
7ответов
334 просмотров

passing a block of memory from a function

I'm trying to figure out how to allocate a block of memory in a function and pass back a pointer to that block through one of the arguments. This is a C program. I seem to be having some trouble. Here's the code: void foo(char *ptr) { if (!(ptr = malloc(size))) printf("error"); ...

0
голосов
5ответов
454 просмотров

Can I use a memory zone to kill iPhone leaks?

I have a C++ class that I'm using from my Objective-C++ controller in my iPhone app. The C++ class does some calculations on some data, returns a result, and then is done -- but it leaks like crazy. I'm wondering if I can somehow make use of Memory Zones (aka malloc zones aka allocWithZone) to so...

0
голосов
1ответов
391 просмотров

iPhone - Instruments ObjectAlloc GeneralBlock

Okay, I have been trying to days to lower the Net Bytes on GeneralBlock 16, I understand that a GeneralBlock is created by the iPhone's OS when creating its own object. Is it possible to lower this alloced memory? I have read in some places that GeneralBlock is something that you shouldn't wor...

8
голосов
6ответов
15238 просмотров

How can malloc() cause a SIGSEGV?

I have an odd bug in my program, it appears to me that malloc() is causing a SIGSEGV, which as far as my understanding goes does not make any sense. I am using a library called simclist for dynamic lists. Here is a struct that is referenced later: typedef struct { int msgid; int status;...

7
голосов
7ответов
5186 просмотров

What is the correct way to handle "out of memory"?

Recently, I work on a video player program on Windows for a CCTV program. As the program has to decode and play many videos streams at the same time, I think it might meet the situation that malloc will fail and I add checking after every malloc. But genrally speaking, in these code of open so...

0
голосов
2ответов
1954 просмотров

iPhone - Multiple CGBitmapContextCreateImage Calls - ObjectAlloc climbing

Has anyone else come across this problem? ObjectAlloc climbs as a result of the CGBitmapContextCreateImage. Does Apple's software not fully releasing the objectalloc? I am resizing images 12 times a second with a NSTimer. During resizing of the image I am also adding a photoshop like Gaussian b...

2
голосов
3ответов
934 просмотров

Any function to query the size of an allocated block?

I realize that any such function is likely to be non standard, but that's ok for my use case. Basically, I need a method (even if it's only exposed through glibc's syscall() interface) that I can pass a pointer to (a pointer that was returned by a previous call to malloc()) that returns the size ...

0
голосов
1ответов
2308 просмотров

iPhone - UIImage imageScaledToSize Memory Issue

I have done research and tried several times to release the UIImage memory and have been unsuccessful. I saw one other post on the internet where someone else was having this same issue. Everytime imageScaledToSize is called, the ObjectAlloc continues to climb. In the following code I am pullin...

1
голосов
3ответов
186 просмотров

Giving an instance of a class a pointer to a struct

I am trying to get SSE functionality in my vector class (I've rewritten it three times so far. :\) and I'm doing the following: #ifndef _POINT_FINAL_H_ #define _POINT_FINAL_H_ #include "math.h" namespace Vector3D { #define SSE_VERSION 3 #if SSE_VERSION >= 2 #include <emmintrin.h&g...

33
голосов
11ответов
47796 просмотров

How can I allocate memory and return it (via a pointer-parameter) to the calling function?

I have some code in a couple of different functions that looks something like this: void someFunction (int *data) { data = (int *) malloc (sizeof (data)); } void useData (int *data) { printf ("%p", data); } int main () { int *data = NULL; someFunction (data); useData (data); ret...

5
голосов
2ответов
2480 просмотров

Overriding "new" and Logging data about the caller

I'm trying to write a memory profiler and so far have been able to get my custom functions to work for malloc, free, new and delete. I tried using __FILE__ and __LINE__ to log the originator inside the overloaded new method, but (as expected) it just gives the details of where the overloaded func...

0
голосов
3ответов
726 просмотров

How to initialize an array after dynamic memory allocation?

I have a function that returns an array of different lengths based on a table lookup. I am malloc'ing required memory for it inside the function but then how can I fill the array from its pointer? The compiler is throwing same error for both of my tries (commented lines). Please help! int lookup...

8
голосов
3ответов
6002 просмотров

Memory allocation and deallocation across dll boundaries

I understand that memory allocations made in one dll then subsequently free'd in another can cause all sort of problems, especially regarding the CRT. These sorts of problems are especially problematic when it comes to exporting STL containers. We've experienced these sorts of problems before (...

4
голосов
6ответов
2470 просмотров

Does going out of scope like this free the associated memory?

I was just wondering, in the following scenarion, is the memory used by 'stringvar' freed after method1 is done executing? // Just some method void method2(char* str) { // Allocate 10 characters for str str = malloc(10 * sizeof(char)); } // Just another method void method1() { char* strin...

12
голосов
7ответов
11756 просмотров

Globally override malloc in visual c++

I'm trying to figure out a way to globally override malloc and related functions in visual c++ (2005). My setup is a dll with statically linked runtime library that consists of both my own c++ code, external c++ and c code. What I want to accomplish is to allow a user of the dll to set their own ...