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
3
votes
0answers
20 views

Using UnsafeMutableRawPointers with Metal buffers in Swift

I've some Metal buffers which I populate with geometry data. Most data consists of Floats, but the buffer also contains custom structs for the tessellation stage. I ...
4
votes
1answer
56 views

C pointer based growable stack rev2

Following on from my previous question: C pointer based growable stack I have made some improvements (hopefully!) based on the very helpful comments and suggestions. I have checked that the stack can ...
7
votes
3answers
1k views

C pointer based growable stack

This is my first attempt at writing a C program, it a generic stack that can grow accordingly. It appears to work correctly, however I am worried that is just a fluke and I could be doing something ...
0
votes
0answers
25 views

Evaluating a Definite Integral, kindly check

The code below does not deal with any numerical-integration or anything related to it — just the basic rule in evaluating a definite integral of the form Ax^2 + Bx + C. I would love to hear from you ...
0
votes
1answer
34 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 ...
5
votes
3answers
595 views

Implementing Sample Abstract Factory Pattern using Smart Pointers in C++

Was trying to implement and example code to smart pointer from link. Is it a good practice? To go with all unique pointers or should we use shared pointers in this case? How can i improve this ? <...
13
votes
3answers
3k views

Hunt the Wumpus

I've made an iteration of the text game Hunt The Wumpus. The specification came from the text Programming Principles and Practice Using C++ by Bjarne Stroustrup. Implement a version of the game "...
6
votes
1answer
161 views

C++ Linked list implementation using smart pointers. Advice on move semantics

As an exercise to familiarise myself with smart pointers, I implemented a template linked list class in C++, closely following the very good tutorial at: https://solarianprogrammer.com/2019/02/22/cpp-...
8
votes
2answers
136 views

C program that reads the description of a deterministic finite automaton and builds it

I just got done coding this C program: Read the description of a deterministic finite automaton from standard input. The first line of input is the number of states in the automaton, n n ...
2
votes
4answers
109 views

I'm deallocating objects created but I'm unsure whether my code is leaking memory or not

I have a simple application which requires the user to input details about students and their grades. I have two different classes Student and ...
2
votes
1answer
61 views

Basic LinkedList implementation [closed]

Please bear in mind, I've only started learning c++ this week, and as such, would love topic suggestions for which I should master, to become better at C++. Below, is my code for a singly linkedlist. ...
2
votes
0answers
28 views

A lightweight version of std::shared_ptr<T> V2

This is a lightweight version of std::shared_ptr<T> called res_ptr<T> This post is a continuation of: A lightweight ...
4
votes
3answers
119 views

Simple shared pointer implementation in a single threaded environment (revised)

std::shared_ptr does not stop you from having the same resource managed by multiple control-blocks (and thus independent sets of shared-pointers), even though it is ...
7
votes
2answers
306 views

A lightweight version of std::shared_ptr<T>

I wrote a simple lighter version of std::shared_ptr<T> called res_ptr<T>. ...
-5
votes
1answer
33 views

Finding frequency of unique array elements by using single pointer [closed]

I am supposed to find the frequency of the unique array elements of a character array via a user defined function like int *unique(char *s), which takes a pointer to a character and returns a pointer ...
10
votes
2answers
765 views

C - Learning Linked Lists, Pointer Manipulation - Store some ints, print and free memory

I'm learning C, and wrote this program outside of my assignments in order to practice pointer manipulation and data structures, step by step. I want to ensure that this program follows well known ...
4
votes
0answers
154 views

Polymorphic deleter for unique_ptr

There is a basic difference in the way C++ manages the deleter for std::unique_ptr and std::shared_ptr, mainly for allowing ...
4
votes
2answers
73 views

Replace part of the string with n size with string of m size

I wanted to understand memory and pointers better before I endeavour into file path manipulations for larger project. This is simple replace part of the string test function that I need to rewrite ...
3
votes
0answers
125 views

Parse DOM Tree in C++ [closed]

Problem I need to read custom text input of a sample document object model (DOM) represented in a json format from a file and store it in a struct I've defined as ...
2
votes
1answer
120 views

A heap-allocated texture class for a console renderer

I am working on a console renderer and I want a heap-allocated dynamic texture class. Since I am quite new to C++, I just want to check the memory management, if I destroy all pointers correctly etc. ...
0
votes
0answers
57 views

Helper to convert arbitrary function into a custom deleter

If you want to use a custom deleter in unique_ptr you either have to pass a functor or the signature of a delete function as template argument. If you have a ...
2
votes
0answers
63 views

Managed Vulkan API Wrapper (create/destroy an instance)

I'm trying to follow this Vulkan API tutorial and have come up with an implementation that I don't completely loathe. The VkUtf8StringArray class is my least ...
3
votes
0answers
94 views

Rich data types - boolean object

Context You can probably skim most of this, it's unlikely to be useful for a review and is just for background info. Also download the files I've tried to create a ...
4
votes
0answers
52 views

Generalizing std::shared_ptr for all handle-types, even non-pointers

I created this shared pointer mainly to use it as RAII for handles that have to be shared between classes or threads. For pointers: It supports raw pointers and pointer to classes and arrays and also ...
1
vote
1answer
133 views

AVL tree implementation using shared_ptr/unique_ptr

I have implemented an AVL tree using shared_ptr. I know that there is an overhead regarding using shared_ptr and instead a unique_ptr could be used. But the thing is that my node contains also a ...
5
votes
1answer
297 views

My unique_ptr implementation

This is my simple unique_ptr implementation. Anything that could be improved upon or should be added? ...
3
votes
2answers
171 views

Merge Sort C++11 C++17

Question Any way I can optimize this further using new C++11 or C++17 features? Would also like feedback on my variable naming, memory management, and style (notice my placement of ...
6
votes
3answers
1k views

Array Dynamic resize in heap

I have answered a Question in Stackoverflow link. a) Create a function called resize that can be used to increase the size of integer arrays dynamically. The function takes three parameters. ...
3
votes
2answers
148 views

Mario Party Snake and Ladders Board

Context Was inspired from this LeetCode post to do my own System Design exercise of the common Snake and Ladders problem. As I was writing the code Mario Party kept coming to mind so I added a little ...
5
votes
1answer
84 views

Implementation of std::experimental::observer_ptr (library fundamentals TS v2)

I made an implementation of std::experimental::observer_ptr (library fundamentals TS v2). observer_ptr basically behaves like a normal pointer and does no ...
7
votes
3answers
1k views

malloc in main() or malloc in another function: allocating memory for a struct and its members

When initializing a struct in C, we can allocate memory inside the main function or within another function and return a pointer to the newly created struct. This ...
4
votes
0answers
299 views

C++ shared_ptr memory pool

I put together this little memory pool class to help avoid the costs associated with heap allocation and deallocation of objects that are frequently created & destroyed. It creates C++ standard <...
4
votes
2answers
100 views

Simple device (fancy) pointer implementation

device_raw_ptr is a simple fancy pointer. It essentially wrap pointers to GPU memory. It's sole purpose is to separate out host pointers from device pointers, i.e. ...
3
votes
0answers
87 views

Writing Go object code that respects Go guidelines

I'm learning Go and I wrote this for a programming challenge. It is working (building and running) but I feel the code is not what Go code should be: Am I using the ...
5
votes
3answers
799 views

Stack Interview Code methods made from class Node and Smart Pointers

Mainly looking for feedback on my use of smart pointers to implement a standard stack. For interview level production code I have also include a namespace and asserts to test my class, let me know if ...
5
votes
1answer
94 views

wrapper for common subset of auto_ptr and unique_ptr API

I read an interesting old question on the Software Engineering SE about how to transition away from std::auto_ptr. So I wrote a wrapper around the common subset of <...
2
votes
1answer
47 views

Queue Interview Code basic methods made from struct Node optimized

Using feedback from my previous implementation I'm writing a very simple Queue of struct Nodes with only these methods get_front(), get_back(), pop_front(), push_back(), and a ostream friend method. I ...
1
vote
2answers
72 views

shared_ptr basic implementation for non array types

This is an implementation to simulate the basic functionality of c++ shared_ptr. This doesn't provide features like custom deleter and make_shared(). I would really appreciate any feedback to improve ...
3
votes
3answers
121 views

Linked List Interview Code methods, runtime, and edge cases refactored

In my previous post I had a number of steps given to me from the accepted answer on how I can write more production ready code. In this post I want this code to be reviewed as near production code I'd ...
2
votes
3answers
106 views

Queue Interview Code basic methods made from struct Node

Thanks for all the feedback, I optimized the code here. Here I'm Writing a very simple Queue of struct Nodes with only these methods get_front(), ...
0
votes
2answers
133 views

Binary Search Tree implementation with unique pointers

I have implemented a binary search tree using templates and unique_ptr in C++ 11. At present, only insertion and deletion are implemented. Please provide your feedback for improvements. ...
4
votes
2answers
2k views

Implementing a binary tree in C++ using “std::unique_ptr”

I have implemented a simple binary search tree class in C++ using std::unique_ptr objects to hold the pointers to each node. In doing this I have come across a ...
1
vote
1answer
102 views

Passing objects atomically across threads without locks or data races for audio synchronization

I am learning about one of the hardest parts of Audio development: the synchronization between the audio thread and the GUI thread. Per the discussion here https://forum.juce.com/t/timur-doumler-...
6
votes
1answer
79 views

Smart pointer like implementations

For educational purposes I implemented standard library smart pointers like class templates. They are definitely not a full replacement for the library classes but I'd like to get some comments on the ...
8
votes
3answers
2k views

Binary Search Tree implementation using smart pointers

I have implemented below code for binary search tree implementation using shared pointer. At present, I have considered only integers. It supports insertion and deletion of values. Also, a print ...
6
votes
1answer
150 views

unique_ptr basic implementation for single objects

This is an implementation to simulate the basic functionality of unique_ptr. This doesn't provide features like custom deleter and ...
3
votes
0answers
43 views

Basic Qt5 UI with button [closed]

I have the following Qt class: mainwindow.h class MainWindow : public QWidget { Q_OBJECT QPushButton* m_button; public: explicit MainWindow(); }; mainwindow....
15
votes
2answers
1k views

C++11 smart pointer 'library'

Edit: NOTE I'm a C++ "beginner" still in undergrad trying to teach myself modern C++ (because they don't do that in uni) so I'm sure this is riddled with errors that I am unaware of. Made a subset of ...
3
votes
1answer
169 views

value_ptr<T> - a C++11 header-only, deep-copying smart pointer that preserves value semantics for polymorphic and undefined types (updated)

My previous iteration was here. I've since finalized the concept as described in the title, and would appreciate any feedback GitHub Link Introduction: ...
1
vote
1answer
96 views

Simple Object Management System

I am attempting to create a fast & robust object management system that allows adding, removing and retrieving objects from a "scene". I am trying to wrap my head around the best way to do this ...

1
2 3 4 5
7