Skip to main content
Filter by
Sorted by
Tagged with
-2 votes
1 answer
106 views

Can the same -- object construction -- be achieved without mixing pointer and value receivers as per official docs ? https://go.dev/tour/methods/8 The problem is Error() cannot be just made with ...
noname7619's user avatar
  • 3,834
2 votes
1 answer
206 views

int main() { const int length = 10000; double *A = new double[length]; double *first = A; double *last = A + length - 1; delete[] A; ptrdiff_t diff = last - first; } In C++, ...
chqrlie's user avatar
  • 152k
4 votes
1 answer
130 views

In the following code, there is a no-throw operator new for the struct TestNew. It is required to further declare it as noexcept to ensure that the constructor is not called, when operator new returns ...
Hari's user avatar
  • 1,985
0 votes
1 answer
184 views

It is usually a problem to draw stepped lines between two points (A) -- (B). I created a macro to do it, but it would be more elegant if there was a "line type" that will take care of it, ...
Benito R. Fernández's user avatar
0 votes
1 answer
140 views

Is it possible to change malloc or new behavior for a somewhat limited scope to actually allocate out of a given buffer that is already allocated? Eg. something like: char buffer[1024]; void main(...
dronus's user avatar
  • 11.4k
11 votes
2 answers
370 views

The following two codes behave as expected: char* test1 = new char[20]{"abc"}; cout << test1; Outputs: abc int size = 20; char* test1 = new char[size]{'a','b','c'}; cout << ...
petat_irrumator's user avatar
0 votes
1 answer
54 views

the below outputs true, meaning that new memory is not allocated for different objects, but they point to the same prototype Noob. function Noob(name, game) { this.name = name; this....
Leafy's user avatar
  • 3
6 votes
2 answers
202 views

I have a user-defined class Person and I want to create a variable-sized array (size taken at runtime) of Person pointers. The following code works as expected. Person **arr = new Person* [size]; ...
Newton's in-law's user avatar
1 vote
1 answer
166 views

I want to redefine new and delete operators to use a custom allocator in a c++ project with multiple translation units. Here are the redefines written in the memops.hpp file: #pragma once #include &...
mdjukan's user avatar
  • 173
1 vote
3 answers
136 views

I would like to transform table like this: Fixed Part Original column U 1 b U 1 c U 1 d X 4 e Y 5 f Z 6 g Z 6 h W 8 i to table like this: Fixed Part New column 1 New column 2 New column 3 U 1 b c d X ...
A Predrag's user avatar
-3 votes
1 answer
166 views

I ran into a problem, from an exercise in Bjarne Stroustrup's book Programming: Principles and Practice Using C++ (2nd edition), at the very end of chapter 17 for the Exercises section, exercise 7: ...
Alexander Reznov's user avatar
1 vote
1 answer
177 views

Say for example I create a vector with new like this: std::vector<int>* pointer_to_vector = new std::vector<int>{2, 4, 6, -1}; Will pointer_to_vector remain valid (not dangling) for the ...
greenlagoon's user avatar
-2 votes
1 answer
166 views

What is the main difference between using the new operator to create an array with trailing parentheses and without? That is, the difference between the following declarations void* ptr = new int[5]();...
Synex's user avatar
  • 213
0 votes
0 answers
32 views

C++ 20 I have this function: int (*funcArrayReturn())[6]; The function returns a pointer to an array int[6] (6 elements aggregated). And I need a pointer of pointers of n elements(in this case 3) ...
BeginnerVS2019's user avatar
0 votes
0 answers
107 views

I wrote this function in Qt 6.8.0: QActionGroup *group = new QActionGroup(ui->toolBar); foreach (QAction *action, ui->toolBar->actions()) { action->setActionGroup(group); QWidget *...
Mark's user avatar
  • 5,355
0 votes
1 answer
155 views

I know how to open a link in a new tab with target="_blank" If I have multiple links on a page and they specify target="_blank" clicking one will open in a new tab but if I go back ...
SimonT's user avatar
  • 556
0 votes
2 answers
47 views

I have the following piece of code - simplified version of what I want to do. But it gives me a recursion error. class File: def __new__(cls, filename): extension = filename.split(".&...
gromajus's user avatar
-1 votes
1 answer
81 views

I am a Javascript novice, while doing a course, everything was going all right until I got to the "prototype chain" part of the course. I am here to ask if someone can explain to me this ...
Matteo V's user avatar
1 vote
2 answers
196 views

Reading: Scalar `new T` vs array `new T[1]` the accepted answer suggests that new T[n] acts as follows (ignoring alignment and the case of n = 0): If n = 1 or a T is trivially-destructible: ...
einpoklum's user avatar
  • 138k
2 votes
0 answers
132 views

C++ always declared the possibility to redefine global memory allocator, redefining ::operator new and ::operator delete in global scope. Example operator_new has code for int. This design considered, ...
Vladlen's user avatar
  • 143
2 votes
1 answer
186 views

I'm observing a difference in the total memory allocation when using malloc versus new in a simple C++ program, as reported by Valgrind. Below are the two versions of my program and the corresponding ...
sajad's user avatar
  • 33
0 votes
0 answers
52 views

I just came across a usage of placement new that I don't understand, which I suppose is not surprising since I've never used it at all. // Copy event type and map data reference from queue entry *...
ROBERT RICHARDSON's user avatar
1 vote
2 answers
123 views

I'm learning C++. The following program looks nice and generic: typedef some_type T; int main() { T* p = new T; } And it indeed works for non-array types like int, etc. However, if I try typedef ...
Ivan's user avatar
  • 419
0 votes
1 answer
403 views

I am just starting out in databricks using SQL, and I just want to select a table and see the fields/columns , I know the table exists when you check the DB catalog but when I try to select it using * ...
Greg Bitterman's user avatar
0 votes
1 answer
95 views

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
  • 3,855
-1 votes
2 answers
125 views

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
  • 3,855
0 votes
1 answer
107 views

jdb's print allows evaluation of expression, but I'm not sure if it's possible to create new objects that way. Any new seems to return just null, e.g.: Thread-0[1] print new java.lang.String("12&...
Computer says 'no'--SOooooo's user avatar
3 votes
1 answer
162 views

As an answer to Idiom for initializing an std::array using a generator function taking the index?, I proposed a way to obtain a properly aligned storage. Yet I think that my solution can be simplified,...
Oersted's user avatar
  • 3,855
0 votes
1 answer
87 views

Let's say the new operator is left for the modern tuple as a rudiment. That is, it can be ignored.I can write it when returning a value from a method or property. But I can't write it when declaring a ...
Konstantin Makarov's user avatar
0 votes
1 answer
141 views

It is said that std::make_shared uses ::new, so if any special behavior has been set up using a class-specific operator new, it will differ from std::shared_ptr<T>(new T(args...)). So, given ...
calvin's user avatar
  • 3,135
3 votes
1 answer
124 views

I understand we can use Class-specific overloads of operator new[]/delete[] to specify our own memory allocation strategy. So I write the following code. I barely want to use the held field to record ...
calvin's user avatar
  • 3,135
0 votes
0 answers
46 views

i have 3 pages , and i have a page where calls the info of the first page and makes calculation and give me error with placeholders (i asked chatgpt) when i try to insert a producy gives me this error ...
bruno silvano's user avatar
0 votes
0 answers
85 views

I am trying to create a dbus proxy using a MyDBUS library I have been assigned The problem is, when I try to do new MyDBUS() the program stops and a malloc error comes out on the screen output, before ...
TheHerborist's user avatar
-1 votes
1 answer
52 views

class A { public void m() { System.out.println("A.m"); } public void n() { System.out.println("A.n"); } } class B extends A { @Override ...
quys's user avatar
  • 31
-1 votes
1 answer
146 views

Problem that appear: Same here: I'm currently facing an issue with deploying a Flutter project after cloning it from a Git repository. Despite successfully cloning the repository, I encounter errors ...
Ginofvs's user avatar
1 vote
0 answers
88 views

Given a buffer char buf[sizeof(T) + alignof(T) - 1]; Is calling placement new that constructs an instance of T on the pointer to the first element of buf that is located at an address which is a ...
CyanideGourmet's user avatar
0 votes
1 answer
35 views

I'm very new to coding. I have looked over MDN, WJ(something). I can't figure out how to put a line break return market.outcomes.map( ({ name, price, point })...
Aewyatt7's user avatar
3 votes
1 answer
97 views

I have lately been experimenting with overloading the new and delete operators, and I noticed something very interesing. When I allocate, let's say, class T with new T(); vs new T[1](), there is a ...
Enigma24's user avatar
4 votes
1 answer
603 views

Using std::print with OpenMP results in a runtime error and I am not sure which path to take in resolving the issue. Consider the code below: /// clang++ -fopenmp -std=c++23 -Wall -Wextra -Werror -g ...
stacker's user avatar
  • 81
0 votes
2 answers
160 views

The new operator in C++ performs the following actions: Allocates Memory: It allocates memory on the heap for a single object or an array of objects. The amount of memory allocated is enough to hold ...
Hee's user avatar
  • 9
-2 votes
1 answer
25 views

[enter image description here](https://i.sstatic.net/JYxhM.png) * type here * xmkosjpscndowdv dwnmo i am try to learn but i have no idea about because i disturb my mind tell me about it any one ...
Ahmad Majeed's user avatar
0 votes
2 answers
44 views

I would like to ask about the difference between using vector and using new, delete in C++. Both new, delete and malloc, free are used for dynamic memory allocation. So why don't we just use vector, ...
Tim's user avatar
  • 3
-2 votes
1 answer
45 views

The GO function doesn't want to work. It's trying to spread a fire with different probailities for different colour but i cant get it to work globals [ initial-trees burned-trees ] breed [fires ...
Eduardo Dorado's user avatar
0 votes
1 answer
92 views

Before anyone start saying that I should use std::string, this is an exercise part of a course, and I'm trying to learn here, not just to make something work. The code runs ok, but I'm trying to ...
Julian A. Tinao's user avatar
2 votes
3 answers
163 views

Let me share my Understanding on new operator. new operator do two jobs. Allocate memory construct memory at same place. The new operator allocates memory using the global method::operator new(), ...
Hardik's user avatar
  • 187
1 vote
3 answers
395 views

I would like to create a class that would work like, for example, the built-in BigInt. So I can do: BigInt('111') BigInt('222').toString() Please guide me on how to code it. I'm using NodeJS with ...
Fox Reymann's user avatar
15 votes
1 answer
600 views

The documentation for the std::allocator<T>::allocate member function says in ([allocator.members]) that: Remarks: The storage for the array is obtained by calling ​::​operator new ([new.delete]...
Daniel Langr's user avatar
  • 24.2k
1 vote
1 answer
871 views

im trying to use ggarrange from ggpubr to have multiple, plots in one general plot. I have my plots saved, and each one has a title, i want to eliminate those titles from each plot when the multiple ...
Eric Derbez's user avatar
1 vote
1 answer
213 views

I was using heap memory as part of a small example, and I ended up writing this: double* p = new double[4] { 0.0, 1.0, 2.0, 3.0 }; ... delete[] p; Later, I wanted to upgrade this to a std::...
alfC's user avatar
  • 16.8k
0 votes
0 answers
57 views

Have a basic snippet of initialization a std::string variable, and track the memory usage of program using overloaded new operator function as below: static uint32_t s_AllocCount = 0; // Overload of ...
Santosh Sahu's user avatar
  • 2,244

1
2 3 4 5
60