2,986 questions
-2
votes
1
answer
106
views
Avoid mixing receiver types in generic constructor
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 ...
2
votes
1
answer
206
views
Is difference between two pointers pointing to the same deallocated array well-defined in C++?
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++, ...
4
votes
1
answer
130
views
Unexpected call to constructor when non-throwing operator new returns a nullptr
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 ...
0
votes
1
answer
184
views
Create a line type in LaTeX/TikZ as -\- and |-| that goes between two points [closed]
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,
...
0
votes
1
answer
140
views
Make malloc allocate from already allocated buffer
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(...
11
votes
2
answers
370
views
Issue with aggregate initialization with the new operator
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 << ...
0
votes
1
answer
54
views
Why does referencing a this.function() in JavaScript not refer to the prototype element?
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....
6
votes
2
answers
202
views
Associativity of '*' operator in a 'new' statement in C++
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];
...
1
vote
1
answer
166
views
Redefining new and delete operators
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 &...
1
vote
3
answers
136
views
Create a new column for each value in another column
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
...
-3
votes
1
answer
166
views
Operators "new" and "delete" in C++
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:
...
1
vote
1
answer
177
views
Are objects created with new guaranteed to stay in the same memory location? If so, does new place things to minimize cache misses & fragmentation?
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 ...
-2
votes
1
answer
166
views
New Operator with and without Parentheses [duplicate]
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]();...
0
votes
0
answers
32
views
How to allocate a pointer of functions that returns a pointer to array of n elements on C++ 20
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) ...
0
votes
0
answers
107
views
Potential leak of memory pointed to by <variable>
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 *...
0
votes
1
answer
155
views
How do you open multiple new tabs with target=_blank and have each in a seperate tab?
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 ...
0
votes
2
answers
47
views
python recursion error, calling classmethod of derived class in __new__ method
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(".&...
-1
votes
1
answer
81
views
I don't understand constructor function with object inside it
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 ...
1
vote
2
answers
196
views
Can I rely on how new[] typically works?
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:
...
2
votes
0
answers
132
views
::operator new overload does not work anymore?
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, ...
2
votes
1
answer
186
views
Difference in Memory Usage Between malloc and new in C++
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 ...
0
votes
0
answers
52
views
How does the behavior of this override of placement new change things? [duplicate]
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 *...
1
vote
2
answers
123
views
C++: array types and new
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 ...
0
votes
1
answer
403
views
I can't select a table from my databricks DBs in SQL - error AnalysisException: Delta table `default`.`incidents` doesn't exist
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 * ...
0
votes
1
answer
95
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 ...
-1
votes
2
answers
125
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 ...
0
votes
1
answer
107
views
Can you create new objects with jdb print?
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&...
3
votes
1
answer
162
views
Correctly deleting a dynamically allocated plain array, allocated with `std::align_val_t` alignment parameter
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,...
0
votes
1
answer
87
views
What is the meaning of the new operator when creating a modern tuple? Or is it a rudiment?
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 ...
0
votes
1
answer
141
views
Can std::make_shared cowork with operator new?
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 ...
3
votes
1
answer
124
views
How to get total allocated size in custom operator delete[]?
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 ...
0
votes
0
answers
46
views
cursor.execute problem , is giving error when i try to insert data
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
...
0
votes
0
answers
85
views
Error when calling new operator - malloc.c:2379
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 ...
-1
votes
1
answer
52
views
Inheritance in Java and its confusing things [closed]
class A {
public void m() {
System.out.println("A.m");
}
public void n() {
System.out.println("A.n");
}
}
class B extends A {
@Override
...
-1
votes
1
answer
146
views
How can I properly run a git clone repo? [closed]
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 ...
1
vote
0
answers
88
views
Using placement new on underaligned buffer in C++
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 ...
0
votes
1
answer
35
views
Line break React
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 })...
3
votes
1
answer
97
views
C++ size of allocated array extraced memory close to returned pointer from malloc
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 ...
4
votes
1
answer
603
views
How to resolve 'weak-def symbol not found' error run-time error for a C++23 program that uses std::println and omp?
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 ...
0
votes
2
answers
160
views
Can out-of-order execution of CPU affect the order of new operator in C++?
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 ...
-2
votes
1
answer
25
views
i have a problem when i remove 3 from new arry( ) there is no changing this thing disturb me what is this
[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 ...
0
votes
2
answers
44
views
What are the differences between using vector and using new,delete in c++?
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, ...
-2
votes
1
answer
45
views
New To NetLogo, don't really know what I'm doing [closed]
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 ...
0
votes
1
answer
92
views
Does this use of "new Mystring" create a memory leak? C++
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 ...
2
votes
3
answers
163
views
Is whether the placement new operator is solely responsible to the construct object
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(), ...
1
vote
3
answers
395
views
How to make a class that returns an instance without `new` keyword
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 ...
15
votes
1
answer
600
views
Why std::allocator<T>::allocate calls ::operator new?
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]...
1
vote
1
answer
871
views
Eliminate titles from plots in order to have one main title
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 ...
1
vote
1
answer
213
views
Is it possible to initialize elements of a unique_ptr array? [duplicate]
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::...
0
votes
0
answers
57
views
C++ std::string initialization using new operator function [duplicate]
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 ...