Skip to main content

All Questions

Tagged with
Filter by
Sorted by
Tagged with
4 votes
3 answers
658 views

Error handling for singly linked list in C

I have seen many list implementations in C in this site; I know its been asked many times. I need some advice regarding: Quality of my code, especially my list library. How to handle errors in main (...
Sai_krishna's user avatar
5 votes
1 answer
190 views

Unit Tests for an Arena Allocator

In my last post about the allocator, I received some comments about unit-tests: The code looks correct on the majority of the cases, I will suggest run valgrind or define a good set of unit tests ...
Harith's user avatar
  • 9,807
7 votes
2 answers
270 views

An Arena/Bump Allocator in C (Follow-up)

This is a follow-up to: An Arena/Bump Allocator in C. LOC: 234. (Not including the sample tests, still quite small and manageable.) The allocator uses C99, but sample tests use C11's ...
Harith's user avatar
  • 9,807
4 votes
1 answer
315 views

Use of double pointers and memory allocation/deallocation

I've made an associative array data structure (more details in the code comments below). What I'm interested in getting a critique on is the usage of double pointers. Are they necessary here? Am I ...
denvaar's user avatar
  • 143
3 votes
1 answer
344 views

First dynamic array in C

I am new to C and have been learning it for about a month now. This is my attempt to implement a dynamic array. My code works, but i don't know whether or not it leaks memory. But my code works as I ...
Logeshwaran K's user avatar
2 votes
3 answers
222 views

Prevent stack memory usage for recursive function in C

This C code does DBSCAN - Density-based spatial clustering of applications with noise. It's a cluster algorithm for turining unsupervised (no labels) data to become ...
euraad's user avatar
  • 183
0 votes
3 answers
78 views

another Merge Sort

I've tried to implement merge sort in c with varying degrees of success, one was correctly sorting the array but leaking memory, one was neither sorting the array and leaking memory. The following was ...
Voiceroy's user avatar
  • 103
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,807
6 votes
1 answer
1k views

Simple stack allocator in C

My plan is to allocate a fixed amount of static memory at initialization (a few MBs), and use a stack allocator for quick temporary buffers. The idea is to avoid calls to ...
KTSnowy's user avatar
  • 63
5 votes
2 answers
649 views

Construct mesh from a point cloud

I have been developing a program with C lately, its purpose over the top is to reconstruct meshes from point clouds which are generated by finding the intersection points of numerous rays fired at the ...
Di0n's user avatar
  • 51
3 votes
1 answer
115 views

Doubly-linked list functions

This is my first time implementing a doubly-linked list. I would like some feedback on my code. Any comment would be appreciated regarding the quality of the code, bad implementation, memory ...
Toideki's user avatar
  • 31
1 vote
2 answers
1k views

C Arena (pool allocator)

I wrote a pool allocator (Arena) for a compiler I'm writing. My use case for this allocator is for storing the parse tree because it allows me to free all the memory at once, so I don't need to keep a ...
Itai Nelken's user avatar
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,167
5 votes
1 answer
589 views

Simple Memory Arena

A memory arena implementation targeting standard C - this is draft code for Slider 3 (https://mrsename.blogspot.com/), a new programming language implementation being developed. Other memory arena ...
Thisis Afal Sename's user avatar
4 votes
1 answer
493 views

Simple slab allocator in C

Here is the plan: a slab takes up 1 page and it has PGSIZE / blocksize amount of blocks the minimum blocksize is 8 bytes, otherwise the pointer to the next block ...
runningupthatroad's user avatar
3 votes
2 answers
202 views

Ray tracer in c running slowly

I was learning C the past few days and decided to make a mini project to get a better feel for it following the Ray Tracing In a Weekend Series. I got it working however I feel like it is pretty slow ...
Aayush's user avatar
  • 61
3 votes
4 answers
2k views

Read arbitrary length strings in C

This is a classic thing to want to do since it's in C that one doesn't have the std::string of C++ and input of Python. I ...
Leonardo Lovera's user avatar
1 vote
1 answer
334 views

Virtual memory manager in C

Virtual Memory manager that has functions, mappage, unmappage, remappage If the physical ...
runningupthatroad's user avatar
3 votes
1 answer
334 views

Bitmap page allocator in C

Bitmap page allocator that scans the bitmap linearly looking for size amount of pages. Everytime it founds a free page, it check if the next ...
runningupthatroad's user avatar
2 votes
1 answer
198 views

Priority Job/Task Queue for Linux (sockets and multithreading)

Preface Please review my implementation of a job queue for linux/unix systems. This is my first time coding in C, although I have quite some experience in C++. I know this is a moderate amount of loc, ...
infinitezero's user avatar
2 votes
0 answers
70 views

Virtual memory manager, physical memory manager and buddy allocator

I'm writing memory manager for my toy operating system and I would like to get some feedback. There is physical memory manager, which uses bitmap, virtual memory manager which uses buddy algorithm for ...
Mateusz's user avatar
  • 21
3 votes
3 answers
808 views

C program that splits the string based on a character

I tried and made a program using my beginner knowledge of C to split a string into multiple sub strings. I just wondered how languages like Python and Javascript implemented the ...
Diwas's user avatar
  • 111
-3 votes
2 answers
915 views

implementing malloc with mmap

I saw this post. Is this a good implementation of malloc using mmap? memory.hpp ...
maya cohen's user avatar
2 votes
0 answers
296 views

OSDEV Physical Memory Manager (PMM) in C

I ported the Physical Memory Manager from Vinix into C for a little OS I'm working on. I'd love to get some feedback. Here's my code: ...
Rayan's user avatar
  • 21
0 votes
1 answer
43 views

OAuth implementation for Puredata

I am managing an OAuth implementation for Puredata (Pd), which is written in C. OAuth can accept RSA keys, but Pd cannot send messages with newlines, so placing private keys will come as a list of ...
Residuum's user avatar
  • 155
2 votes
2 answers
247 views

C library implementing binary trees

This is my first attempt at writing a library in C. I have only included tree creation and in-order traversal function for now, but will expand to have more functions soon. I have three files, ...
Vedant Jadhav's user avatar
4 votes
2 answers
268 views

Linked list implementation for a beginner in C

So I've decided to dabble a bit into C, and while it's trippy as heck I've finished an implementation of a linked list for practice. I've pretty sure there's some type of obscure bug or memory leak in ...
k huang's user avatar
  • 141
1 vote
2 answers
904 views

Dynamically allocating a 3D-array in c

I want to use dynamically allocated data, corresponding to a 3D array in a C program. After using the data, I would like to properly deallocate the data again. My approach is as follows: ...
Alf's user avatar
  • 111
7 votes
2 answers
804 views

2D Maze Game with Monsters

Introduction I've started to learn C programming a bit and wanted to create a simple 2D console game. Let me first introduce you to the game level/map structure: ...
never_feel_mellow's user avatar
4 votes
2 answers
1k views

CSV file reader

Hi, I asked this question over on stack overflow. However, they closed the thread and suggested to ask it on code review. So here I am :) The code below is an updated version of my original code, ...
WuselDusel's user avatar
7 votes
2 answers
1k views

Hack machine language assembler as required for project 6 of Nand2Tetris

This is the implementation of the Assembler required to parse source code written in the Hack Machine Language and output it to a 16-bit binary file. After writing one go in Swift, I decided I wanted ...
Henry Cooper's user avatar
5 votes
6 answers
3k views

Implementation of itoa which allocates the string

This is my implementation of itoa() (Integer to Alpha), which converts an integer to a string. Memory management and optimization is important. The caller is not ...
toni's user avatar
  • 61
0 votes
1 answer
50 views

SubImage function implementation in C

This is a follow-up question for Two dimensional gaussian image generator in C, Two dimensional bicubic interpolation implementation in C and A SubPlane Method for Generic Two Dimensional Data Plane ...
JimmyHu's user avatar
  • 5,510
5 votes
2 answers
423 views

Two dimensional gaussian image generator in C

This is a follow-up question for Image Processing Median Filter in C. I am attempting to create a two dimensional gaussian image like below in C. The formula is as follows. The experimental ...
JimmyHu's user avatar
  • 5,510
3 votes
3 answers
2k views

Image Processing Sobel Edge Detection in C

This is a follow-up question for Image Processing Median Filter in C. Under the same tiny bmp image read / write framework, a sobel edge detection function has been performed. The experimental ...
JimmyHu's user avatar
  • 5,510
4 votes
4 answers
1k views

Image Processing Median Filter in C

I am attempting to perform Median Filter with size 3 x 3 in C language. The function MedianFilter33 has been implemented as follows. The experimental implementation ...
JimmyHu's user avatar
  • 5,510
1 vote
2 answers
914 views

A [non-destructive] better (not really) `strtok` function

The first time I used strtok, it felt, well, weird. But after a while, I became quite used to it. In a way it was simple. Soon after reading a bunch of Stack ...
debdutdeb's user avatar
0 votes
2 answers
135 views

Fixed memory manager in C

I decided to not use heap in my program and create a custom memory manager to retrieve memory chunks from a big global array of uint8_t(u8). I chose u8 since 8 bits is a byte. The very big ...
cynnad's user avatar
  • 79
4 votes
2 answers
191 views

My own function for copying memory in C

I have written a function that copies memory from one destination to another. I would like you to view my code and tell me if I have to fix something. That's the code: ...
user avatar
1 vote
1 answer
742 views

dynarr - yet another simple C dynamic array library

I wrote my own dynamic array library for C as I was not happy with the others I found. It is very crude but the basic logic should be correct, it mainly revolves making ...
TheDcoder's user avatar
  • 135
1 vote
2 answers
635 views

C ArrayList implementation

I have written a ArrayList class in C and I just wanted some criticism on what I can improve on. Any criticism helps, and I was wondering if there is any better way of doing error handling other than ...
CLox's user avatar
  • 419
3 votes
1 answer
151 views

Smart/Dynamic array in C

I attempted to make a smart/dynamic array implementation in C which is supposed to be a hybrid between a C++ vector/stack/queue. This is what i came up with: Header (smart_array.h): ...
cynnad's user avatar
  • 79
3 votes
2 answers
302 views

Reference-counted smart pointer in C

About I've been experimenting with gcc's __cleanup__ attribute, and thought it'd be a great fit for a memory-safe smart pointer for C. This is the implementation. ...
Ricardo Silva's user avatar
4 votes
1 answer
148 views

Bump Allocator in Linked List

Here is my code for implementing a linked list with custom allocators (the standard malloc/free and a simple bump allocator). I appreciate any comments or critiques about architecture, formatting, and ...
sdasdadas's user avatar
  • 557
3 votes
1 answer
403 views

Maintain a list of contacts in C

I have a function that gets a string and prints it as a message. Then, it reads the text from stdin, saves it in a pointer and sends it back: ...
RedYoel's user avatar
  • 311
5 votes
1 answer
861 views

3D Direct Convolution Implementation in C

For my project, I've written a naive C implementation of Direct3D convolution with periodic padding on the input. Unfortunately, since I'm new to C, the performance isn't so good. By convention, all ...
lxiangyun93's user avatar
4 votes
2 answers
1k views

Malloc and free

I'm looking for help speeding up some code I'm tinkering with. The rest of the code, as well as my 'benchmark', can be found here. ...
Lev Knoblock's user avatar
3 votes
2 answers
294 views

String input and split functions in C

I've some functions targeted to simplify working with strings in some of my other projects. I'd like feedback on this code and whether or not the implementation is efficient and memory safe. I work ...
Chase's user avatar
  • 197
0 votes
1 answer
54 views

Code to write a C template file [closed]

I am writing code to write a C template file; the executable takes two arguments (main) <file name> and ...
Shashwat D's user avatar
3 votes
3 answers
298 views

Rotate square matrix clockwise by 90degrees

...
kesarling's user avatar
  • 352