Skip to main content
The 2024 Developer Survey results are live! See the results

All Questions

Tagged with
0 votes
1 answer
44 views

C++ Primer 5th Ed - Stanley Lipmann: Question on shared_ptr.unique() used in conjunction with shared_ptr.reset()

First we have a shared_ptr defined as below: shared_ptr<int> p(new int(42)); According to the text below: The reset member is often used together with unique to control changes to the object ...
yapkm01's user avatar
  • 3,703
0 votes
0 answers
31 views

Getting heap storage with proper alignment in C++ for overaligned type

In some use case, you'll need to allocate storage before creating objects inside this storage. Then in order to create these objects, you may need to use placement new: T *pobj = new(pstorage); yet ...
Oersted's user avatar
  • 1,708
-1 votes
1 answer
63 views

Getting heap storage with proper alignment in C++ for non-overaligned type

In some use case, you'll need to allocate storage before creating objects inside this storage. Then in order to create these objects, you may need to use placement new: T *pobj = new(pstorage); yet ...
Oersted's user avatar
  • 1,708
0 votes
1 answer
60 views

LLVM Analyzer Garbage value

I work on a custom container and I manually allocate some heap memory: template<typename element_type> class MyClass{ element_type* m_data = nullptr; std::size_t rows, columns; // assume ...
Goug's user avatar
  • 27
-2 votes
0 answers
52 views

c++ heap vs stack allocation for append function call [duplicate]

If I have a string in C++: std:string a = std:string("haha"); Does it get allocated on the stack since it's a local variable? Or since it's the std::string type, does it directly go on the ...
hooistheman's user avatar
-3 votes
2 answers
63 views

Define/Initialize Vectors on Stack vs Heap [closed]

I declare two vectors in my class header file as follows: struct MYDATA { uint8_t A = 0; uint8_t B = 0; }; std::vector<MYDATA> vector1; std::vector<MYDATA> *vector2 = new std::...
Torisoft's user avatar
-3 votes
1 answer
79 views

How is Numpy able to get an array size at run-time?

In C++ the size of an array must be determined at the compile-time. I want to write a simple code in C++, say, to do a naive matrix multiplication with itself (for a matrix that is square in size) and ...
MOON's user avatar
  • 2,732
0 votes
1 answer
108 views

"A breakpoint instruction (__debugbreak() statement or a similar call) was executed" without breakpoint :(

Member.h pragma once #ifndef MEMBER_H #define MEMBER_H #include <iostream> #include <string> using namespace std; class Member { private: char* m_id; char* m_pwd; char* ...
 Mei's user avatar
  • 1
1 vote
0 answers
65 views

unknown memory leak in Qt6 C++

I installed deleaker and decided to test it on a small code, as a result, I got 1 error about a memory leak, which, as for me, should not be and I do not understand where it comes from ...
zxctatar's user avatar
0 votes
2 answers
80 views

Correct syntax to access array elements in structs?

First-year comp sci student, and first time posting on here. I have a struct: struct Student{ string name; int studentID; int numTests; int *testScores = new int [TESTS]; //Access with ...
Noah Stromberg's user avatar
0 votes
2 answers
102 views

Does Stack being limited in size mean i can only get limited pointers to objects in heap?

if stack size is 1MB, does that mean i can only get less than 1000000/8 pointers to allocate ints in heap? (considering 1MB free stack) yeah i know you might not want to make that many individual ints ...
Nemexia's user avatar
  • 139
-3 votes
2 answers
125 views

Why is there no time cost to large stack allocations

I tried this quick-bench test and I'm finding that it's the same cost timewise to allocate 200 bytes as it is to allocate 2000000 bytes. How could that possibly be?
bobobobo's user avatar
  • 66.6k
0 votes
1 answer
93 views

corruption memory on heap only when using one specific function

I am creating a application that downloads stuff from a url into a file and having a big problem with getting the substring of the url to use to create as the downloads name. I have spent the last 4 ...
alus21's user avatar
  • 7
-3 votes
1 answer
84 views

pointers from heap and instances from stack C++ [closed]

My purpose is to determine if I should deallocate using delete a variable to a pointer stored in a linked list... I had the idea to consider that any pointer allocated in the heap will be strictly ...
David Harouche's user avatar
0 votes
3 answers
111 views

how to return an array of struct pointers?

i want to return an array of struct pointers. i want the array of struct pointers became accessible in the main function. but it always breaks. i have tried using smart pointers but it seems like they ...
Ayodya Enhanayoan's user avatar

15 30 50 per page
1
2 3 4 5
99