Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.

Questions tagged [pointers]

In computer science, a pointer is a programming language data type whose value refers directly to (or "points to") another value stored elsewhere in the computer memory using its address.

Filter by
Sorted by
Tagged with
14 votes
5 answers
2k views

I implemented FFT in C

I wrote Cooley-Tukey's FFT algorithm in C. And I want to know how safe is this code? Is it just trash? How can I make it more memory safe? ...
RudraSama's user avatar
  • 181
9 votes
2 answers
861 views

My shared_ptr implementation

I would like to ask for a code review of my shared_ptr<T> implementation for design, code style. Any nitpicks will extremely useful for me. The features ...
Quasar's user avatar
  • 639
10 votes
6 answers
2k views

k-Nearest Neighbors algorithm in C

I've been learning C for a while, and I decided to make a simple kNN program. What can I do to improve the program? Am I doing memory management right? Can the structure of the code be improved in ...
Super Tux's user avatar
  • 313
4 votes
1 answer
126 views

Maze game from book Design Patterns with smart pointers and polymorphism

The Design Patterns book chapter 3 about Creational Patterns starts with a maze game. They use the maze as an example throughout the chapter and instead of rooms they have also things like enchanted ...
elehtine's user avatar
  • 165
3 votes
1 answer
130 views

Leveraging EBCO (Empty Base Class Optimization )in a Simplified Smart‐Pointer with Custom Deleters

I’ve been experimenting with a minimal unique_ptr–style class to see Empty Base Class Optimization(EBCO) in action when the deleter is empty: ...
sam's user avatar
  • 441
7 votes
3 answers
1k views

C++ implementation of Go inspired cancellable context

I am trying to create golang inspired cancellable context in C++ for use in worker threads and other tasks. I have tried to avoid using raw pointers, but ever since I started writing C++ code, I ...
Mahdi Chaari's user avatar
4 votes
1 answer
151 views

Compute index in a ring buffer

I have a buffer implemented as a fixed-size std::vector with two begin and end pointers ...
Phil's user avatar
  • 41
14 votes
2 answers
588 views

Custom implementation of `std::unique_ptr<T>`

I skimmed through the documentation on cppreference.com and put down the basic functionalities expected out of a unique_ptr<T> implementation. I coded up a ...
Quasar's user avatar
  • 639
6 votes
2 answers
792 views

polymorphic message container [closed]

Any comments/suggestions on this design? I just want to hold onto an ordered collection of messages. Each message can be one of several types. I'm using some code analogous to this currently in a ...
Taylor's user avatar
  • 303
5 votes
3 answers
433 views

Implementation of arrays that store their size

In this code I implemented arrays that store their own size before the first element. To access it you need to go back exactly sizeof(size_t) bytes back. To free it,...
yurich's user avatar
  • 157
3 votes
2 answers
175 views

Todo List app using C

I just learned to deal with pointers and memory allocation stuff. Using that, I built a todo list app, and it works as far as I tested it. I didn't account for many user errors, so any suggestion to ...
Sarthak Hingankar's user avatar
5 votes
3 answers
912 views

Safe(r) / Easier Pointer Allocation Interface in C (ISO C11)

I spent like half an hour programming up a set of functions to make the allocation / deallocate of pointers easier within a bigger project. I felt that they were satisfactory, but was wondering if ...
Zenais's user avatar
  • 75
1 vote
1 answer
285 views

A unique_ptr-like class, for spans instead of raw pointers

Introduction / Motivation I like the CADRe (a.k.a. RAII) resource management idiom in C++. And I like std::span's; or perhaps I should say, I dislike the use of ...
einpoklum's user avatar
  • 2,099
3 votes
1 answer
111 views

Compare and merge sets from unstructured variables for automatic differentiation

I have developed an automatic differentiation module for my software. Usually AD comes in two forms; forward mode or reverse mode and very clever approaches, beyond me, might mix both. Typically the ...
Attack68's user avatar
  • 633
4 votes
1 answer
188 views

Trie implementation using std::shared_ptr

I've implemented a basic Trie that is supposed to work only with lowercase English letters. ...
csmathhc's user avatar
  • 143
2 votes
2 answers
309 views

Optimizing Subarray Removal: Can the Removal Process be Enhanced for Better Efficiency?

The only requirement is that it has to be done by pointers: And it returns the amount of removed numbers because of the way of output that is set in the main. The function, using exclusively pointer ...
eminbihh's user avatar
7 votes
3 answers
2k views

"Smart" (ish) pointer in C

I am a programmer with a primarily Rust-based background who has nonetheless taken an interest in C lately due to its simplicity and minimalism. However, one of the things I miss most from Rust is ...
JS4137's user avatar
  • 195
4 votes
1 answer
176 views

Member (virtual or not) function to C callback by generating static version at compile time

I've started to write a header-only implementation of callback for member functions : ...
hl037_'s user avatar
  • 141
1 vote
3 answers
283 views

A shared pointer which can delete the managed object before the usage count reaches zero

When I was working on my game engine, I needed to know if a game object has been destroyed or not. So, I decided to use std::shared_ptr. But the standard shared ...
LooksForFuture's user avatar
2 votes
2 answers
604 views

C++ std::shared_ptr implementation

Took a shot at implementing std::shared_ptr, with a thread-safe refcount and weak count. Didn't do weak_ptr, I'm doing this for ...
jdav22's user avatar
  • 381
4 votes
2 answers
457 views

A memory leak-free RAII wrapper around two raw pointers

As a practice of implementing RAII-enabled class, I prepared a class called DynamicWallet that wraps around two raw pointers. I am well aware that using smart ...
D.J. Elkind's user avatar
2 votes
0 answers
74 views

Reusable storage for array of objects V4

Here is a thirdfollow up on Reusable storage for array of objects, Reusable storage for array of objects V2 and Reusable storage for array of objects V3, taking into account the provided answers. The ...
Oersted's user avatar
  • 337
1 vote
1 answer
91 views

Reusable storage for array of objects V3

Here is a second follow up on Reusable storage for array of objects and Reusable storage for array of objects V2, taking into account the provided answers. The following code should be compliant at ...
Oersted's user avatar
  • 337
3 votes
1 answer
105 views

Reusable storage for array of objects V2

Here is a follow up on Reusable storage for array of objects, taking into account the provided answers. The following code should be compliant at least with gcc, <...
Oersted's user avatar
  • 337
4 votes
2 answers
575 views

Reusable storage for array of objects

My goal is to have a memory pool non-template class that is used to store arrays of objects. The same memory pool object must be reusable for a different array (difference size, different type and/or ...
Oersted's user avatar
  • 337
5 votes
2 answers
306 views

C++ UniquePtr Implementation

Took a shot at implementing std::unique_ptr. Code: ...
jdav22's user avatar
  • 381
7 votes
2 answers
284 views

shared_ptr implementation code - first cut

I've written an implementation of shared_ptr. It doesn't support weak_ptr (yet) but below is the code. I'd appreciate any feedback, comments. ...
Greg's user avatar
  • 71
2 votes
3 answers
151 views

Exercises 5.1 from K&R (function to read an integer value)

As written [above], getint treats a + or - not followed by a digit as a valid representation ...
igor's user avatar
  • 21
7 votes
3 answers
271 views

C++ String Class Reimplementation

I started learning C++ about a week ago and I was hoping somebody can critique my code. I decided to implement my own basic String class just for the sake of applying all that I've learned about ...
Janriz Libres's user avatar
3 votes
1 answer
191 views

Implementing The Decorator Design Pattern in C++

I recently tried to implement the decorator design pattern in C++. Here is the code in full: ...
Sc2046's user avatar
  • 33
-1 votes
1 answer
333 views

Copying allocated data into std::map in a smart way [closed]

I come across a problem and I solved it. The solution works but I have some feelings that there is something wrong with my solution/code. To be clear, let's assume that cars on the race track transmit ...
unique's user avatar
  • 235
7 votes
2 answers
256 views

simple connect four game

I made a simple connect four terminal game in C and was wondering if I could get feedback on it. I mainly want to know where pointers could have optimised my code, and if there are any major ...
Willem's user avatar
  • 71
4 votes
1 answer
164 views

C# wrapper that binds to Rust FFI, for the purpose of running CavalierContours functions in Unity

I have attempted to write c# bindings for a Rust library. I have never worked with unmanned code / languages before. Superficially this code does work with no apparent bugs or memory leaks. I want to ...
arcadeperfect's user avatar
5 votes
1 answer
367 views

Port Node and TreeBuilder from Python to C++

I am trying to port a TreeBuilder Python class to C++, keeping the structure as close as possible to the original. Here is a simplified Python version: https://onlinegdb.com/I4dg0hCtg The purpose of ...
Paolo's user avatar
  • 63
7 votes
3 answers
2k views

Implementation of a shared pointer constructors and destructor

I am writing my simple shared pointer. I am asking to review existing functions (understand that my implementations is not full, e.g now operator*) Review please ...
mascai's user avatar
  • 459
5 votes
1 answer
1k views

Dynamic array type using void pointers C

I made my own dynamic array type using void pointers. I'd like to know what you think of my implementation. void pointers are nice but I fear they may be inefficient. The compiler cannot tell what ...
Lead Vaxeral's user avatar
12 votes
10 answers
3k views

Trim leading/trailing space in a string

I'm practicing C and wrote a function to trim leading/trailing spaces in a string: ...
roadsidejesus's user avatar
8 votes
1 answer
962 views

Rust: Splitting a mutable slice into disjoint, but non-contiguous subslices

For some context, this is inspired by my attempt to solve this SO question. I have a mutably borrowed slice representing a 2D array, and I want to split the borrow such that I can access all the rows ...
FZs's user avatar
  • 183
1 vote
1 answer
170 views

Readlines abstraction for Golang

I've just started learning Golang and was solving some problems which required me to read lines of text from a file. I decided to abstract away the reading part so that I can use Go's ...
smac89's user avatar
  • 1,539
3 votes
1 answer
343 views

C void* Generic Hash Table

Some time ago I tried to make a generic linked list in pure C (no external libraries, only the C standard library) using void*s here. Building on top of that and ...
404 Name Not Found's user avatar
2 votes
1 answer
329 views

Intrusive smart pointer implementation

I have homework in college to implement intrusive smart pointers. ...
Edziju's user avatar
  • 319
8 votes
1 answer
747 views

C void* Generic Linked List

I once tried to make a generic linked list in pure C (no external libraries, only the C standard library) here using C macros. With the same restrictions as in the previous attempt, this time I'm ...
404 Name Not Found's user avatar
1 vote
1 answer
59 views

Moveable Points - Update variable without Re-referencing variable? Event Subscriptions? (C#, Unity)

So I have this helper script that I use to move points around manually while debugging: ...
FaffyWaffles's user avatar
1 vote
1 answer
144 views

Class that can only be created and deleter through smart pointer

I would like to expose a nullable referance of a "mesh" object, so I am returning a const pointer. However, I explicitly want to prevent anyone handling this from deleting the object. The ...
Jay's user avatar
  • 212
4 votes
1 answer
544 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
2 votes
1 answer
465 views

C Program - Camel Case (creates or splits camel case variables, methods and class names.)

I have written a program in C, which does the following operations: creates or splits Camel Case variable, method, class names. Input format Each line of the input file will begin with an operation ...
jr.çhåvez__07's user avatar
2 votes
0 answers
90 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
2 votes
1 answer
186 views

Function to find the first pair where the sum zero. using 2-pointers approach

Here is the function called sumZero, where it should return the sum of any two numbers in the array to sum upto zero. where the array is a sorted array. My approach: Using 2 pointers approach, calling ...
RONE's user avatar
  • 131
3 votes
3 answers
902 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
2 votes
2 answers
5k views

A simple logging library in C

I've created a simple logging library in C which I can use in my other projects. I wanted to get started in software development using the C language, and this is my first attempt at writing something ...
Vedant Jadhav's user avatar

1
2 3 4 5
9