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.
2
votes
1answer
23 views
4
votes
1answer
42 views
Pointer handle with some runtime checking
This is a pointer class of mine that I would like to have reviewed. Right now it only allocates in the stack and has no copy or move operations.
...
2
votes
2answers
91 views
Yet another smart pointer implementation for learning
I based this implementation on CountedPtr in The C++ Standard Library book by Nicolai Josuttis (page 222) and also available online here.
I know that I can use the C++11 smart pointers but this is a ...
-3
votes
0answers
20 views
Transposing matrices [closed]
The idea is to use functions in order to transpose matrices. For some reason, C won't allow me to return the arrays themselves so I tried using pointers. I'm not very good with pointers, so this ...
5
votes
3answers
164 views
Printing the contents of a string array using pointers
I'm currently studying C and I'm trying to just print the contents of a string array. I'm using pNames to point to the first char pointer and iterating from there.
...
2
votes
2answers
52 views
Basic myVector class raw vs smart pointer
I'm writing a myVector class for a class I'm taking. I don't believe I'm "strong" with smart pointers right now, so that's my question. This is just an excerpt ...
4
votes
4answers
86 views
Printing out all possible combination of printable ASCII 7-bit characters to stdout
This takes over 60 minutes to execute. The program is small in size, about 16kb. I am thinking that the repeated calls to printf slows it down significantly, rather ...
5
votes
4answers
341 views
Using std::unique_ptr and std::move
I'm trying out new things (on class Inproc), specifically using std::unique_ptr and ...
-3
votes
2answers
82 views
Simple auto_ptr [closed]
I wrote my own simple auto_ptr class, but detected some magic.
C++ Header file
...
4
votes
0answers
82 views
Wrap function pointers in template classes
I'm working on a C++ library for Arduino and other embedded systems.
I'm currently working on wrapping up function pointers and member-function pointers into two C++ template classes (function and ...
1
vote
2answers
62 views
Binary search tree with templates
I am currently attempting to become proficient in C++ and started by implementing a basic binary search tree. Most of the programming I have done is in Ada, Python and C.
I would like to be able to ...
5
votes
2answers
190 views
Constructing a graph and performing a depth-first traversal
Please review the use of pointers and design in graph construction code and its depth first traversal. I haven't used smart pointers as I want to understand any issues in following implementation with ...
0
votes
2answers
56 views
Deleting values from std::vector of different types
I need to make a vector of different types and be able to delete the values (please ignore anything else but deleting the values for now). Is the next code safe to delete the values?
...
0
votes
1answer
82 views
Polymorphic template cloning class
I have a requirement of a templated clone() method which Base classes can implement through an ICloneable interface and all the ...
10
votes
2answers
536 views
Smart but simple pointers
For practice, I've implemented my own smart pointer class. It's a 'unique pointer', meaning it doesn't allow copies of itself (when copying from a into ...
1
vote
2answers
76 views
Speeding up and shortening a loop [closed]
I'm still relatively new to C++ and I've written a program that could do with being a bit shorter and faster.
I use this same set of for loops many times to cycle through the whole tree of values. ...
6
votes
4answers
139 views
Custom class for a borrowed unique_ptr<T>?
In C++11, I tend to have master objects that maintain sole ownership of a collection of some children objects. Let's assume these children objects are non-copyable (for instance, ...
4
votes
1answer
897 views
Implement a string in reverse using pointers and recursion
I'm trying to reverse a string using pointers and recursion, and I send it a char array. Is this the best way, or is there a better one?
...
3
votes
3answers
214 views
Simple shared pointer
I wrote a simple shared pointer, which I think works pretty well. I would like to see your review of it.
This is the header file:
...
6
votes
2answers
221 views
Layer Stack class to practice std::shared_ptr
The following three source files is to define and test a class StackLayer.
While it was written in a need for scalable layer-based architecture design, it was also ...
5
votes
2answers
185 views
Singleton typed memory manager
For my resources management, I wanted the objects allocated on the heap to be in a contiguous block of memory. Obviously, each data type then has to have their own chunk of memory. I could have used a ...
4
votes
1answer
118 views
Builder/named argument/fluent interface pattern with unique_ptr
I'm trying to figure out the cleanest way to implement a fluent interface with unique_ptr and other "modern" C++ language constructs. Here's my first attempt:
...
8
votes
3answers
630 views
Travelling Salesman in Qt
I am writing a recursive function based on the Travelling Salesman Problem.
Is this a correct way of doing things, or am I creating memory leaks?
Prerequisites are:
a two dimensional matrix ...
7
votes
2answers
824 views
3
votes
1answer
170 views
Auto-recycling C++11 polymorphic smart pointers
I've recently read an interesting blog post by Philipp Zschoche:
it explains how it's possible to avoid unnecessary allocations/deallocations by keeping track of previously allocated memory in a ...
1
vote
1answer
45 views
Trimming exactly two white spaces from string at O(N) [closed]
This is the optimized code I have written for removing/trimming one white space from a given string. I'm required to remove exactly two spaces from the string at the same cost of \$O(N)\$ by ...
2
votes
2answers
110 views
Pointers for struct and `for`
I know something about pointers, but I'm trying to check my knowledge on a sample. Can somebody check if my code is good? I don't think that I should use pointers in these ...
3
votes
2answers
562 views
Binary Tree with C++11 smart pointers
I'm trying to replace the use of raw pointers with smart pointers in my C++ code. The following bit is from my first attempt at a self-balancing binary tree, though there is nothing self-balancing at ...
0
votes
1answer
96 views
One more shared pointer
Here's a (hopefully) better shared pointer than the previous one. The improvement is that now it should also accept function and lambda objects. Should work fine with threads.
...
10
votes
3answers
3k views
Implementation of stack using pointers
Please review my code and let me know how I can possibly improve it.
...
4
votes
0answers
264 views
Smart pointer memory pool
I'm using a third-party library which utilizes boost::shared_ptr for memory management.
The problem is that I need to allocate many objects and I have detected ...
6
votes
2answers
217 views
How best to keep track of an unknown number of objects?
I have a manager class that will manage an unknown number of objects. I'm currently storing the objects in a NSMutableArray object, and when I need to find one, I ...
5
votes
2answers
569 views
Proposed solution to dangling pointers: a non-owning smart pointer
The lifetimes of various objects referring to each other are sometimes only known at runtime. For example, in a side scrolling shooter game, a HomingMissile ...
4
votes
1answer
104 views
Creating a list using a struct in C
I just got into structs and I decided to create a list using them:
...
6
votes
4answers
210 views
Pass pointer data across multiple functions
I would like review on the following dynamic memory allocation process and suggestions on whether there are any memory leaks. Following code is not real code in use, but I'm trying to understand ...
3
votes
1answer
56 views
getword that properly handles undersores, string constants, comments, or preprocessor control lines
Our version of getword does not properly handle underscores, string constants, comments, or preprocessor control lines. Write a better version.
This is the exercise 6-1 and can be foud on K&R ...
10
votes
2answers
442 views
C struct or pointer to struct?
I am currently using this code (and more) to deal with 2D matrices. I am not very proficient in C, so I am not quite sure, if this is a good way of doing it.
I've seen other people in similar ...
10
votes
1answer
129 views
1
vote
2answers
154 views
10
votes
3answers
859 views
Tail implementation in C
Write the program tail, which prints the last n lines of its input. By default, n is 10, ...
6
votes
2answers
269 views
Linked list implementation in C
I'm learning C for mainly for fun and to get a better understanding of how things work under the hood (most of my experience lies with high-level languages). I've been following quite a few books and ...
2
votes
1answer
121 views
Bidirectional map based on memory manipulation
This is a bidirectional map implementation that stores the values as pairs on the heap, and uses pointer arithmetic for efficient lookup.
codepad link, may be easier to read
...
4
votes
1answer
88 views
Writting day_of_month and month_day with pointers instead of array indexing
Rewrite the routines day_of_year and month_day with pointers instead of indexing.
The exercise is quite simple, this is the ...
4
votes
2answers
117 views
Optimising LinkedList class - Part 2
This is part 2. My problems are with too any pointers and with long body code in the following functions:
...
4
votes
2answers
157 views
Optimising a LinkedList data structure - Part 1
I have implemented a linked list. I feel I overdid it with pointers, used old standards and C++11, and I ended with too many lines of code. I will make my quotations into two parts: one for the ...
7
votes
1answer
66 views
Storing lines in an array
Rewrite readlines to store lines in an array supplied by main, rather than calling alloc() to maintain storage. How much ...
3
votes
1answer
88 views
C dynamic array and pointers
I've written an implementation of a dynamic array in C, but I'm not sure if my implementation is correct... This is what I'm worried about: if I add an element, will it remain in the collection? This ...
2
votes
1answer
119 views
Pointer version of itoa
Rewrite appropiate programs from earlier chapters and exercises with pointers instead of array indexing. Good posibilities include getline(Chapter 1 and 4), ...
10
votes
2answers
225 views
strend, function that checks the occurence of a pattern at the end of a string
Write a function strend(s, t) which returns 1 if the string t occurs at the end of ...
10
votes
4answers
2k views
Pointer version of strcat
Write a pointer version of the function strcat that we showed in Chapter 2: strcat(s, t) copies the string t to the end of ...