new-operator

How to invoke aligned new/delete properly?

北城以北 提交于 2021-02-18 21:58:27
问题 How do I call new operator with alignment? auto foo = new(std::align_val_t(32)) Foo; //? and then, how to delete it properly? delete(std::align_val_t(32), foo); //? If this is the right form of using these overloads, why valgring complaining about mismatched free()/delete/delete[]? 回答1: exist very basic principle - the memory free routine always must match to allocate routine. if we use mismatch allocate and free - run time behavior can be any: all can be random ok, or crash by run-time, or

How to invoke aligned new/delete properly?

允我心安 提交于 2021-02-18 21:53:08
问题 How do I call new operator with alignment? auto foo = new(std::align_val_t(32)) Foo; //? and then, how to delete it properly? delete(std::align_val_t(32), foo); //? If this is the right form of using these overloads, why valgring complaining about mismatched free()/delete/delete[]? 回答1: exist very basic principle - the memory free routine always must match to allocate routine. if we use mismatch allocate and free - run time behavior can be any: all can be random ok, or crash by run-time, or

C++ array of a self-defined class, no matching function call

僤鯓⒐⒋嵵緔 提交于 2021-02-11 06:26:29
问题 I was building a Huffman coding tree and I wanted to create an array where each position contains a separate tree, as the code follows: // Number of initial nodes int number; cin >> number; int* weights = new int[number]; for (int i = 0; i < number; i++) cin >> weights[i]; // Convert to huffman tree with one element intHuffTree* tree = new intHuffTree[number]; for (int i = 0; i < number; i++) { tree[i] = intHuffTree(weights[i]); } where the class is defined like: // Huffman tree with integers

C++ array of a self-defined class, no matching function call

☆樱花仙子☆ 提交于 2021-02-11 06:26:10
问题 I was building a Huffman coding tree and I wanted to create an array where each position contains a separate tree, as the code follows: // Number of initial nodes int number; cin >> number; int* weights = new int[number]; for (int i = 0; i < number; i++) cin >> weights[i]; // Convert to huffman tree with one element intHuffTree* tree = new intHuffTree[number]; for (int i = 0; i < number; i++) { tree[i] = intHuffTree(weights[i]); } where the class is defined like: // Huffman tree with integers

new[] doesn't decrease available memory until populated

狂风中的少年 提交于 2021-02-08 12:24:09
问题 This is in C++ on CentOS 64bit using G++ 4.1.2. We're writing a test application to load up the memory usage on a system by n Gigabytes. The idea being that the overall system load gets monitored through SNMP etc. So this is just a way of exercising the monitoring. What we've seen however is that simply doing: char* p = new char[1000000000]; doesn't affect the memory used as shown in either top or free -m The memory allocation only seems to become "real" once the memory is written to: memcpy

Browser for CSS shaders? [closed]

陌路散爱 提交于 2021-02-07 14:23:21
问题 Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 4 years ago . Improve this question Is there a browser which supports CSS shaders? 回答1: At the time of this writing, CSS Custom Filters, formerly known as CSS Shaders, are not available in any browser. They were an experimental feature available in WebKit Nightly and Chrome (under a flag) for a

Why use a new call with c++ vector?

…衆ロ難τιáo~ 提交于 2021-02-07 10:33:16
问题 The code vector<someType> myVector; dynamically allocates memory, so any elements stored will live until a delete is called. So how is the following, vector<someType> *myVector = new vector<someType>(); , different (other than being a pointer) from the earlier one? Is there a double allocation happening here? Everyone mentions it is evil to mix a vector with a new call, but why? If it is evil, why is it acceptable code for the compiler and when is it okay to use? 回答1: Your first statement is

javascript new keyword and memory leaks?

依然范特西╮ 提交于 2021-02-07 10:24:22
问题 let x = new MyClass(); ...[more code] let x = new MyClass(); Will the first instance of MyClass get garbaged collected automatically? Or do I need to explicitly x = null or something like that before the second assignment, in order to avoid a memory leak? 回答1: JavScript's memory is managed automatically, so objects that are deemed "unreachable" are collected by the garbage collector. In the example you provided, the object stored in x will be garbage-collected so long as it isn't reachable

delete partial memory of the pointer

爱⌒轻易说出口 提交于 2021-02-05 11:58:48
问题 Is there any way i can delete the partial memory of the pointer.? for example char *c = new char[1000]; sprintf(c,"this is it"); As it can be seen a lot of memory is getting wasted here. can I free the memory more than the required.? 回答1: Not directly. The best you can do in C++ is to make a new copy that's the right size and delete the old one. There's no analog of C's realloc . 回答2: Unless your system is a RAM-restricted embedded system, why bother? Just use ginormous buffers and include a

Why do I have to pass new keyword?

旧时模样 提交于 2021-01-28 08:35:13
问题 I have the following code: val fsm = TestFSMRef(new SenderCollectorFsm) And do not understand, why do I have to pass to TestFSMRef an instance. Lets look at the definition of TestFSMRef: object TestFSMRef { def apply[S, D, T <: Actor: ClassTag]( factory: => T)(implicit ev: T <:< FSM[S, D], system: ActorSystem): TestFSMRef[S, D, T] = { val impl = system.asInstanceOf[ActorSystemImpl] new TestFSMRef(impl, Props(factory), impl.guardian.asInstanceOf[InternalActorRef], TestActorRef.randomName) } T