Questions tagged [new-operator]
new is a language construct that dynamically allocates memory from free store and initialises the memory using the constructor.
2,850
questions
0
votes
0
answers
18
views
How can i implement an autoupdater to a Retail POS?
I was reading possible solutions, but im new programming.
I Need to create a program that run the retail POS and comprobate the version of each DLL, then kill the retail POSS and make the update.
I ...
0
votes
0
answers
66
views
How to avoid global operator override for specific class?
After override global operator new, I want to record all memory usage with global_map.
static std::map<void*, uint64_t> global_map;
void* operator new(size_t size) {
void* p = malloc(size);
...
0
votes
1
answer
57
views
How to custom memory allocator for a static library writen in C++?
To count the memory usage of a static library A, we will write a custom memory allocator or rewrite operator new/delete.
Since there are other libraries in the application, we only want the usage of A....
-1
votes
0
answers
15
views
Different size flex-items, and costum flex-container start and end positions [closed]
I am trying to replicate a similar header like the one in the image below, that header according to the inspect element is a flex container. However i'm not being able to achieve the same spacing ...
5
votes
1
answer
72
views
The lookup of the deallocation function called when the initialization of the object a new expression created by terminates by throwing an exception
The following code:
#include <new>
#include <iostream>
#include <cstdlib>
struct alignas(32) S
{
S() {throw 1;}
void* operator new(std::size_t count, std::align_val_t al)
...
-1
votes
0
answers
15
views
Remove newline character enclosed in between double quotes in pipe delimited file
I have pipe delimited file with newline character and random double quotes text enclosed in between double quotes
Sample data:
1|"abc "def
Ceg" agsh "agsh"afsgh"|dfsb
2|...
-3
votes
1
answer
32
views
C# creating variables, Int a = new int();
What is the difference between:
a) int A = new int();
and
b) int A = 0;
0
votes
0
answers
80
views
Why clang works ok with runtime size and initializer list for dynamic array, while gcc (strange behavior) and msvc (internal compiler error) not?
I know that modernly raw pointers should be usually avoided, with some exceptions. My question is about an interaction that I saw since I started my studies and I still can't understand it.
#include &...
-1
votes
0
answers
35
views
Oculus Account New [closed]
How does one create an oculus account without Facebook or Instagram? I have made an account in stack overflow as well as exchange but when I try to log into the oculus app it doesn’t work.
-1
votes
0
answers
91
views
What should I use instead of operator new?
In this CppCon talk, Andrei Alexandrescu gives some problems with operator new and then says
I unrecommend operator new for any serious user of memory
allocation... pretend [operator new] doesn't ...
-3
votes
1
answer
46
views
In C++, is there a pattern to make sure the new object pointer generated by the class static method will be deleted? [closed]
Is there a pattern to make sure the new object pointer generated by the class static method will be deleted?
I have a base class here.
// abstract class
class Expression{
// method here ...
};
...
0
votes
0
answers
30
views
How can we create a metaclass so as to customize the behavior of `__call__()` for types instantiated from the meta-class?
Consider the following code:
class Mehta(type):
pass
class Klass(metaclass = Mehta):
def __init__(self, *args):
pass
def __call__(self, *args):
return "LIZZY THE ...
0
votes
1
answer
30
views
rotating ellipse on screen
Hi all im struggling to get my ellipse(s) to rotate in p5js any help would be grand!
Cant seem to figure out how to make it work as now it just moves on the screen without rotating... lol. I am new to ...
0
votes
0
answers
14
views
How to find what custom rom was installed
My ex got ahold of my phone, I know there is a custom rom installed. How do I get my phone back to normal? I do not have a computer.
0
votes
0
answers
11
views
How to add a column "restored" and write inside "ok" or "nok" in an output csv
What I have is a powershell script that find the SamAccountName of a User AD from an input csv file with the corresponding EmployeeNumber. The script tells me in the output csv file if the user ...
0
votes
1
answer
71
views
C++ - Should you delete allocated memory in the copy assignment operator of a class that uses raw pointers?
I am still somewhat new at c++, and I am a little confused about this.
Say we have struct struct_x that uses raw pointers as attributes. Should the raw pointers then be deleted in the copy assignment ...
0
votes
2
answers
52
views
Why does the freed memory is less than allocated memory when overloading new and delete operators?
I created a class and overloaded new and delete operators to print the size of memory allocated/freed. In the example below, it allocated 28 bytes but frees 4 bytes. Why?
#include <iostream>
#...
-2
votes
0
answers
15
views
This link should open in a new tab target="_blank" not working
Link not opening in a new tab even if i use target blank
Below is my complete code. i just need the link to be opened in a new tab. for now it is working and opening in the same tab.
<div class=&...
0
votes
3
answers
92
views
C++ Creating Dynamic 2D Array With One Statement but Without auto
I've seen that a dynamic 2D array in C++ can be created as follows:
auto arr{ new int[nRows][nCols] };
nRows and nCols are compile-time known and the size of the array will not change during runtime.
...
1
vote
1
answer
62
views
The term 'csc' is not recognized as the name of a cmdlet, etc. (New to C#. Learning from 'C#8.0 and .NET Core 3.0)
Very new to programming here. I am going through 'C# 8.0 and .NET Core 3.0 book'. I tried to check which versions of the C# compiler are available, but the term 'csc' isn't recognized. I have ...
0
votes
1
answer
52
views
Different ways to instantiate classes
Aside from personal preference is there any difference between:
SomeClass SomeInstance = new SomeClass();
SomeClass SomeInstance = new();
and
var SomeInstance = new SomeClass();
1
vote
2
answers
67
views
operator aligned new/delete vs operator aligned new[]/delete[]
I was writing an aligned operator for vector and I realize that I don't know the difference between operator aligned new/delete vs operator aligned new[]/delete[].
Both seem only de/allocate memory, ...
0
votes
1
answer
66
views
Can we use useState() at multiple time or is there any limit to use it in React Js?
Can we use useState() at multiple time or is there any limit to use it in single component in React Js.
0
votes
0
answers
42
views
assigning different value to javascript arrays created using new
I have written a webpage that helps in solving wordle using javascript.
It is similar to https://tryhardguides.com/wordle-solver/.
The difference is that my webpage can be run offline as all 2308 ...
0
votes
0
answers
22
views
I created a brand new script, however validator says I have more than 1 "html"?
I know this question has been asked heaps of times, however the answers didn't help me, below is the code, I don't understand how there is an error, i've seen many others code that have "html-/...
0
votes
1
answer
39
views
Unity how to add a fade transition after hitting play button?
I want to make my scene transition with a fade after hitting the "play" button I created. Currently when you hit the play button it transitions to the next game scene. I want to implement a ...
0
votes
1
answer
72
views
why the destructor is called only one time when the constructor is called 5 times? [duplicate]
I'm trying to learn more about C++ ,int this code I'm allocating an array of A's (5 in this case), what I understand that 5 A's will be allocated ...so the compiler will call 5 times the constructer ,...
-1
votes
2
answers
56
views
how can i force to make it to only string
Hello How can i force to make the nname to only string input because even though i put number it still continue to the next function and i only like it to be a name of the people nname= str(input()) ...
0
votes
1
answer
45
views
Vectors of Pointers passed into different functions
I'm trying to practice with the usage of the new operator to create objects. I'm having some trouble with adjusting my code to manage the new pointers to the objects that I created.
Here's my code:
#...
-2
votes
1
answer
62
views
Is there a reason why the delete[]p; will not delete my array values? [duplicate]
I am currently using C++ on VScode with C/C++ and CodeRunner application. For some reason, even though adding the delete[]p in my code, the values in the following array remain there. Can someone ...
0
votes
0
answers
6
views
R - Create a new timepoint that is closest to another timepoint
I have one score at Time1 (T1). In my sample, every ID has a different T1. Each participant did questionnaires (Q) every 3 - 6 months or not (There is missing data). I need to be able to find the ...
0
votes
0
answers
28
views
Floating Action Button problems
I'm trying to make a FAB launch another activity in my Application. It'll open the Maps API.
I'm new at this an keep getting errors or my app crashes.
<com.google.android.material....
0
votes
0
answers
37
views
New Google Sites Migration
I have a need to migrate the New google sites to MS Sharepoint sites. My code works for classic google sites but not for New google sites. Are there any api's, sdk's availbale from google which can be ...
0
votes
0
answers
12
views
how to stop SqlToosResourcesProviderServices
I'm using node.js, brew services and mysql -u root -p to start the server.. everything turns off when I command it to except my activity monitor (mac os) says SqlToolsResourcesProviderServices is ...
0
votes
0
answers
35
views
why the second new failure cannot invoke the override delete?
class Test {
public:
Test() {
throw "error";//throw exception deliberately
}
void operator delete(void* ptr, string msg) { // 0
cout << msg << endl;
...
2
votes
2
answers
74
views
C++ placement new, Invalid read and InvalidInvalid free() / delete / delete[] / realloc()
I'm experimenting the usage of placement new to try to understand how it works.
Executing the code below:
#include <iostream>
#define SHOW(x) std::cout << #x ": " << x <...
0
votes
1
answer
35
views
Scope of dynamic (multidimm) array when initialized with pointer and new
I'm royally confused right now. I have seen similar questions asked, and my implementation seems to be along the lines of these solutions, but I just can't get it to work.
I need to have a UtilClass ...
0
votes
0
answers
19
views
I don't understand how new node has been created without pointer to node [duplicate]
Here`s some code example. Can someone tell what does it mean?
new (&(newNode->value)) T(val);
0
votes
1
answer
43
views
I need to set a losing condition for a simple game I am making in Unity c#
I am working on a simple mobile game in Unity. There is a cannon at the bottom of the screen and you shoot small bullets at moving platforms at the top of the screen. For my lose condition I need to ...
1
vote
1
answer
64
views
git - create new repo from existing one, keep history
I'm not sure how I should do that. I read threads on stack but I don't want to break anything on the old (existing) repo so I think its better to ask...
I want to create new repo from existing one, ...
0
votes
0
answers
74
views
How to understand overload of new? [duplicate]
Im quite noob in c++ so i ask you to explain it the in the simplest way you can, please!
I know that to say:
int * p = new (x) int;
is like to say:
operator new (sizeof(int), x);
But why?? Can ...
0
votes
1
answer
41
views
Where can I see all objects I can make with the "new" operator in Chrome?
Title basically. I want to know all the objects I can make with new in chrome - which are specific to Chrome/Chromium. For example:
new MessageChannel();
new TextEncoderStream();
new EyeDropper();
...
0
votes
1
answer
79
views
c++11 - private constructor still callable
I have somewhat the following definition of a class in MainLoop.h:
class MainLoop {
private:
static const MainLoop &s_instance;
public:
static inline const MainLoop &...
0
votes
1
answer
79
views
Creating a POS System in python using Tkinter now I have this error
I'm just creating my receipt function and my calculation function for my POS system every time I press the "Americano" Button which should add it to the treeviewer list Which it does but it ...
0
votes
0
answers
10
views
I am unable to create a new Option in Navigation drawer using Android Stuido 2021 version
I have tried to create a new option rather than pre-built three Options(Home,Gallery,Slideshow) with the same functionality as shown in the previous three's.But I m unable to open the newer option's ...
0
votes
0
answers
34
views
C++: memory-management issue and new-operator [duplicate]
I'm new to C++ (which is probably obvious based on below code ...) and don't manage to solve the following problem: when running below program, (*c).print(); prints values that are obviously wrong but ...
1
vote
1
answer
46
views
C++: SIGTRAP error in custrom String class
I have scoured the internet for the past two days and can find no reason for this to be occurring.
My string class works in the way one would expect: it starts with an initial block of contiguous ...
0
votes
0
answers
19
views
MYSQL using IF statement in a trigger to concatenate
I am having some issues with my database rn. In short, I want it so that when adding a row, if certain column with data type enum is equal to one of the choices, then a fixed VARCHAR can be added to ...
0
votes
2
answers
23
views
New rows based on a string - Pandas. python
I have this pandas df
show_id type title director cast
s1 Movie Duck the Halls Dave Wasson Chris Diamantopoulos, Tony Anselmo,
...
0
votes
1
answer
63
views
Difference between uniform initialization vs new operator
Let's assume that I have the following class:
Class Foo {
public:
int j;
Foo(int i){
j = i;
std::cout << j << endl;
};
}
I am new to C++ and I'm confused about ...