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,274
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
20k 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
631 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,533
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,533
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
  • 2,287
16 votes
1 answer
57k 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
14 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.2k
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,421
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 \...
Martin York's user avatar
  • 94.3k
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 ...
ex nihilo's user avatar
  • 699
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
914 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
394 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
4k 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 ...
DeiDei's user avatar
  • 551
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
20k 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
1k 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
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
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
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
3 answers
969 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
113 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
  • 65.3k
11 votes
1 answer
373 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.5k
10 votes
5 answers
2k 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
5k 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
10 votes
3 answers
57k views

Implementing an ArrayList

I implemented ArrayList functionality in C as follows: ...
Amr Ayman's user avatar
  • 853
10 votes
2 answers
6k views

Yet another implementation of malloc() in C

I'm really curious to know someone else's opinion on this implementation. Specifically, I would be interested to know the way you would have implemented it. Here the list of issues I've found with in ...
nullbyte's user avatar
  • 415

1
2 3 4 5
13