Skip to main content
The 2024 Developer Survey results are live! See the results

Questions tagged [malloc]

The malloc function performs dynamic memory allocation in C and is part of the standard library. Use this tag for questions about usage, behavior and implementations of malloc.

1 vote
0 answers
82 views

Difference in Memory Usage Between malloc and new in C++

I'm observing a difference in the total memory allocation when using malloc versus new in a simple C++ program, as reported by Valgrind. Below are the two versions of my program and the corresponding ...
sajad's user avatar
  • 13
1 vote
1 answer
28 views

Can't put values together into struct that is initiated by pointer and malloc [duplicate]

Just a simple struct called person, inside I need to store name and age. I'm trying to dynamically allocate memory for my struct. Without using pointer: #include <stdio.h> #include <stdlib.h&...
cutelittlebunny's user avatar
-6 votes
2 answers
71 views

malloc(): corrupted top size on deleting an entry from binary file [closed]

I AM CREATING A SCHOOL MANAGEMENT SYSTEM . WHEN I TRY TO DELETE A STUDENT AFTER ADDING ONE I AM GETTING "malloc(): corrupted top size" ERROR .CANT FIND THE REASON.I AM A BEGINNER , HELP ...
ASHNA A's user avatar
0 votes
0 answers
61 views
+50

Large allocation metadata is causing fragmentation and wasting DRAM in jemalloc when using extent hooks

I am writing a simple custom extent allocator that returns extents from a pre mapped area (this way I can explicitly control the mapped area -- and the allocations in it). I am using the dev branch of ...
idle_cycles's user avatar
0 votes
1 answer
53 views

How to get rid of C6387 warning on call to fwrite function?

In Visual Studio 2022, I am getting the following warning when I call fwrite. Warning image C6387 It says: C6387:'fout' could be '0': this does not adhere to the specification for the function 'fwrite'...
lussco's user avatar
  • 3
0 votes
0 answers
17 views

Initializing an array created with malloc with arbitrary values

I need to create large float arrays using malloc, to be able to free the memory when I don't need the array anymore. The values are arbitrary, meaning they are not all zeros or ones, much more random ...
Fabrice Auzanneau's user avatar
0 votes
0 answers
69 views

How do I solve "realloc(): invalid next size" error?

Here is the section of code where my program crashes: if (fromNode != toNode) { pthread_mutex_lock(&mtxs[fromNode]); g->out[fromNode]++; if (g->in[toNode].index == g->in[...
XOpt 6's user avatar
  • 11
0 votes
3 answers
87 views

Error in assigning values to memory location with for loop [duplicate]

I have just entered the world of C programming, and I'm currently learning how to use malloc & free. I've written a short excercise code to printf the string entered with scanf, and I am having ...
Woodrow's user avatar
  • 27
0 votes
0 answers
15 views

How to Comparing Custom Malloc Package (CMU Malloc) with Standard Allocators Using Benchmarks

I am currently working on the CMU Malloc Lab and I have implemented my own malloc package in mm.c. I would like to benchmark my implementation not only with the Malloc Lab grading script but also ...
Kim TaeHyeon's user avatar
4 votes
2 answers
125 views

Function to clear allocated memory is not working

I'm trying to make a DTC in C. This is the structure of the nodes: typedef struct node { int value; struct node *lower; struct node *higher; } node; To free the memory allocated using ...
Sarvesh Pande's user avatar
3 votes
2 answers
148 views

Malloc sometimes fails immediately after a free

I want to test my code in low memory situations. I wrote this function with setrlimit to limit the available memory : unsigned short int oom_enable = 0; char* _oomfill = NULL; uint32_t oom_setup(...
François Cerbelle's user avatar
0 votes
1 answer
35 views

How to know heap overflow point?

I'm attempting to write a program that determines all palindrome within a given range. My program calls a function (number of digits) that returns the size of an integer (ie. 400 would be 3 as it has ...
Ratdude's user avatar
  • 67
0 votes
1 answer
103 views

How to free memory for an array allocated by malloc?

I have 2 variants of code: 1st: void PrintMem(const int* memarr,const size_t size) { for (size_t index = 0; index < size; ++index) { std::cout << '<'<<(index+1)<<&...
vansergh's user avatar
1 vote
1 answer
78 views

wrong values when displayed : C pointer or malloc issue?

My program multiplies a matrix 1 by a matrix 2. The matrix 3 is the result. I can display matrix 1 and matrix 2 with the correct values but I am not able to display though the same function the ...
EagleStar's user avatar
  • 199
0 votes
3 answers
116 views

Using the malloc function once initializes all uninitialized variables with a 0

The malloc function is not supposed to initialize any value to any variable it is used on, like the calloc function does. Why then do I keep getting the initialized value of even other varibales to ...
Aditya Bhardwaj's user avatar

15 30 50 per page
1
2 3 4 5
621