Skip to main content

Questions tagged [memory-management]

Memory management is the act of managing computer memory by allocating portions of memory to programs as well as freeing memory so that it can be re-used.

Filter by
Sorted by
Tagged with
31 votes
1 answer
3k views

Yet another 'any' class implementation, named 'some'

This is a follow-up of 'any' class implementation. After posting my answer, I kept working on the code towards parameterizing with respect to memory management as I had promised. I ended up in some ...
iavr's user avatar
  • 2,284
28 votes
5 answers
5k views

C++ Vector Clone

I'm learning C++, so I decided to make a simpler clone of std::vector. Concerns: I have seen people defining methods outside of the class, and only prototyping ...
internet_user's user avatar
27 votes
1 answer
20k views

Efficient smart pointer implementation in C++

The idea behind this is mainly educational but I might even consider using it in reality if turns out to be good. Here's my first try at implementing smart pointers: ...
mmirzadeh's user avatar
  • 411
25 votes
5 answers
21k views

Implementing realloc in C

I have an assignment to implement realloc in C, This's my code please review it. ...
Junius L's user avatar
  • 779
25 votes
6 answers
6k views

C++ string operators

I'm trying to practice my C++ on my own; At the moment I'm trying to implement the concept of operator overloading making my own string class/function. I think I handled this correctly; the code ...
Dries Reyskens's user avatar
22 votes
1 answer
2k views

Tiny Lua library to get char pointer from string

Background I'm using Lua with luaglut to do some OpenGL stuff. The luaglut API is almost identical to the gl/glut C APIs. Sometimes, gl functions want a pointer to some data, for example: ...
Dagg's user avatar
  • 4,531
22 votes
1 answer
644 views

Aligning your heterogenous uninitialized memory to make the processor happy

After learning more about memory alignment and how it can impact processor data access, I tried to find something in the standard that offers proper memory alignment inside blocks of raw memory that ...
user2296177's user avatar
  • 3,543
21 votes
3 answers
9k views

A vector-like polymorphic container to store objects from a type hierarchy in contiguous memory

Normally, in order to have a polymorphic collection, we store pointers to a base class: ...
user2296177's user avatar
  • 3,543
17 votes
5 answers
5k views

malloc() and free() implementation

I'm looking for a code review of my custom memory allocation library (written for educational purposes), which includes malloc(), ...
Harith's user avatar
  • 9,422
16 votes
1 answer
58k views

Alternative to setInterval and setTimeout

JavaScript's setTimeout() and setInterval() are evil and not precise: Both functions have a delay of a varying quantity of ...
cocco's user avatar
  • 303
15 votes
6 answers
11k views

Small one time pad encryption program

This one time pad encryption program I have written (basically just an XOR "encryption" program) seems to be working fine, compiling nicely (gcc -o ./OTP.c), and doing what it's supposed to. However I ...
youjustreadthis's user avatar
15 votes
2 answers
22k views

Reading n chars from stream to string

I need to read n chars from a binary file into a string. Currently, what I do is: ...
svick's user avatar
  • 24.3k
14 votes
2 answers
3k views

malloc() and free() for Linux with system calls

I have written an implementation of malloc() and free() for Linux using the sbrk() system ...
jess's user avatar
  • 1,378
14 votes
2 answers
8k views

Fixed-size block allocator

I have written a fixed-size block allocator implementation and would like some feedback as to what I could improve in my code and coding practices. Your comments or notes are welcomed! An auxiliary ...
se0808's user avatar
  • 303
14 votes
2 answers
5k views

Asynchronous Circular Buffer in C#

Preamble I want to be able to test methods which communicate over a simple exclusively asynchronous two-way stream-like interface which may underneath use any of a number of communication methods (e....
VisualMelon's user avatar
  • 7,431
14 votes
2 answers
2k views

Free a binary tree without using recursion or allocating memory

As the title says, the objective is to free a binary tree without using the stack or allocating memory. This was required for a kernel module where resources were limited. Result has a complexity of \...
Loki Astari's user avatar
  • 95.4k
13 votes
5 answers
5k views

Zero-initializing large dynamically allocated arrays of double

Arrays of double can be zero-initialized with the { 0 } initializer, which works even on systems that have a binary ...
ad absurdum's user avatar
13 votes
3 answers
7k views

Structure to ByteArray Extension

I have a need to turn various structures into byte arrays to be sent over serial port to another machine. I created generic extensions to turn any structure into a byte array and from a byte array ...
RubberDuck's user avatar
  • 30.8k
13 votes
1 answer
3k views

C++ class for aligning objects on the stack

I wrote a short class which allocates objects on the stack and aligns them to a specific memory address. Alignment makes sense for some objects (i.e. some SIMD intrinsics require aligned data). I ...
cruppstahl's user avatar
13 votes
2 answers
920 views

Dynamic memory management for a class hierarchy of geometric shapes

The task was to write function that compare areas of two random generated geometric shapes (circle, square, rectangle) using base class with virtual function. Am I doing it right in terms of memory ...
Paweł Dymowski's user avatar
13 votes
4 answers
409 views

Bare-bones string library

After years of criticizing others, I've finally found the time and worked up the courage to polish up one of my bits of code and solicit criticisms of my own. This is a simple dynamic-string library ...
Corbin's user avatar
  • 10.6k
13 votes
1 answer
8k views

Resource Manager in C++ for Games

I'm currently writing a small game, needing some advice for things I could do better on this resource management system. Speed is not crucial, and I have no memory budget. The goal is to load and ...
K.K. Slider's user avatar
12 votes
2 answers
2k views

Weapon and Hero classes

For me as a complete newbie to the world of C++, getters and setters are a rather confusing topic. There seems to be a wide range of opinions on what constitutes a sound use of getters and setters. In ...
Michael Langbein's user avatar
12 votes
2 answers
2k views

Taking arbitrary length input in C

Instead of having to use something like char buf[100500] and hope that no possible user input could be longer than 100500 bytes, I decided to make the following ...
galois's user avatar
  • 289
12 votes
4 answers
5k views

C++ Doubly Linked List Implementation

Does anyone have suggestions on how to improve this? Specifically: Am I passing and returning references correctly to prevent unnecessary copying? Am I using destructors and the delete keyword ...
user146276's user avatar
12 votes
3 answers
3k views

Stack implementation with move semantics

I have implemented a basic stack just for fun. I've just started learning about move constructors and assignment and move semantics as a whole, so I would really appreciate some feedback as to whether ...
Ivaylo Valchev's user avatar
12 votes
3 answers
7k views

Random permutation of int[] and ArrayList<Integer>

I wrote a simple program using int[] and ArrayList<Integer> which aims to get a random permutation output between 1 to 10, ...
niese's user avatar
  • 157
12 votes
1 answer
21k views

malloc(), free(), realloc() using brk() and sbrk()

I recoded malloc() by using brk() and sbrk(). I just want some "reviews" to see if it is ...
nookonee's user avatar
  • 223
12 votes
3 answers
2k views

Doubly linked list with no apparent memory leaks

I've run my code through Valgrind and managed to not get any memory leaks based on the test code in main. I'm looking for things that I may not have thought to check for, and ways to improve my code ...
Sunde's user avatar
  • 223
12 votes
2 answers
2k views

Implementation of a lock-free fixed-sized allocator

This question now has a follow-up: Implementation of a lock-free fixed-sized allocator - follow-up - with commented code I've tried implementing a lock-free fixed-size allocator while trying to ...
cr_oag's user avatar
  • 565
12 votes
2 answers
2k views

Using the CMA-ES algorithm to optimize the position of wind turbines

I have an implementation of an optimization algorithm called the Covariance Matrix Adaptation Evolutionary Strategy (CMA-ES). I am using this algorithm to optimize the position of wind turbines inside ...
user3181463's user avatar
12 votes
1 answer
3k views

My malloc() in C using mmap()

My latest school project was to implement malloc(), free(), realloc() and ...
Jon Nimrod's user avatar
12 votes
1 answer
4k views

Arena memory allocator

I'm not exactly sure if this is technically an "arena allocator" but it serves a similar purpose: providing a fast way to allocate a lot of objects that can all be freed at once. ...
chbaker0's user avatar
  • 803
11 votes
5 answers
2k views

Static factory function and lifetime

I'm trying to teach myself C++ at the moment, after years of C# and other managed languages. The class in question is a Level in a game, and the idea is to ...
Michael Stum's user avatar
11 votes
4 answers
4k views

C++ dynamic array implementation

As a C++ beginner coming from Java, I have become increasingly confused on the topic of memory management and how to avoid memory leaks. Is the code below risking a memory leak that I'm not currently ...
ethan warco's user avatar
11 votes
5 answers
4k views

Python's .split() implemented in C

I'm new to the C programming language and I just made a basic version of Python's split() function using C. Note: A major functionality I chose not to implement is ...
Dewamuval's user avatar
  • 223
11 votes
2 answers
5k views

malloc implementation

Please give me some feedback to my malloc implementation. I implemented this design to understand the basic concept. ...
Gerald's user avatar
  • 111
11 votes
1 answer
1k views

Customization of memory class C++

I have implemented a customized memory allocation class template for an assignment. Codes are commented; Hopefully it's clear. I would love to know if there is any way to make the code more optimized. ...
starrk's user avatar
  • 369
11 votes
4 answers
3k views

"Restaurant" HackerRank challenge in C

I don't write C all that often, so things to look for would be memory leaks and such. I also recognize that I'm not validating the user input as well as I could - I could use some feedback on how I ...
Josiah's user avatar
  • 391
11 votes
3 answers
4k views

My own little memory manager in C

I have implemented a simple version of malloc() and its associated functions, free(), ...
CompSciple's user avatar
11 votes
3 answers
4k views

Checking for palindromes using dynamic memory allocation

This is a homework assignment, but it's already done and it's not for a grade; it's meant as a refresher for the rest of the course. I've never done anything with dynamic memory allocation in C before,...
Thomas's user avatar
  • 213
11 votes
2 answers
2k views

Linked list arithmetic

I am practicing for interviews and I tried solving the problem on my own and got a solution. I was wondering how can I improve the performance and memory on this program? The problem performs ...
Liondancer's user avatar
  • 1,499
11 votes
2 answers
7k views

Extracting the last component (basename) of a filesystem path

...
Sean Perry's user avatar
  • 1,199
11 votes
3 answers
2k views

Reusing strings read from I/O

I am working on an application that reads lots of data from the network and puts it in a grid. I noticed that I could save some memory by reusing existing strings instead of always using the new ...
Chris's user avatar
  • 213
11 votes
1 answer
13k views

A working stack allocator

Here's an absolutely essential piece of C++ lore, a stack allocator, that will allow you to, say, allocate strings and vectors on the stack. There are 2 stack allocators I know of, here and here. The ...
user1095108's user avatar
  • 1,434
11 votes
3 answers
976 views

Garbage collection in JavaScript multiplayer game

I am currently creating a Multiplayer Game using node.js and web sockets. The client side is receiving the positional information and applying it to all the players on the client side. Each client ...
user avatar
11 votes
1 answer
115 views

Longest lines using priority queue

Inspired by a comment on this question, I thought I'd exercise my C skills by implementing something like it using a priority queue. The idea is to be able to invoke the program like this: ./...
Edward's user avatar
  • 66.5k
11 votes
1 answer
380 views

Wrapping types with alignment requirements

Visual Studio 2013 still doesn't support the alignas keyword in C++11. This causes some problems with alignment of types in various situations. Thankfully the ...
Emily L.'s user avatar
  • 16.6k
10 votes
5 answers
3k views

Implementation of a two-dimensional array in C

I implemented a two-dimensional array in C and would like to know if the implementation is sound in terms of Memory management Potential bugs and other side effects that I missed Code style (...
Gilfoyle's user avatar
  • 1,125
10 votes
5 answers
6k views

Memory-safe file-reading in C

I am trying to write a single function that will read a certain number of bytes from a C file, or the entire file, based on the arguments. I want it to be memory-safe of course, and deal with ...
Tom's user avatar
  • 567

1
2 3 4 5
13