new-operator

How to prevent a globally overridden “new” operator from being linked in from external library

霸气de小男生 提交于 2019-12-02 21:11:36
In our iPhone XCode 3.2.1 project, we're linking in 2 external static C++ libraries, libBlue.a and libGreen.a. libBlue.a globally overrides the " new " operator for it's own memory management. However, when we build our project, libGreen.a winds up using libBlue's new operator, which results in a crash (presumably because libBlue.a is making assumptions about the kinds of structures being allocated). Both libBlue.a and libGreen.a are provided by 3rd parties, so we can't change any of their source code or build options. When we remove libBlue.a from the project, libGreen.a doesn't have any

How do “Object()” and “new Object()” differ in JavaScript?

不羁岁月 提交于 2019-12-02 21:08:04
In JavaScript, what's the difference between var x = Object(); and var x = new Object(); ? This is pulled directly from the ECMAScript specification : 15.2.1 The Object Constructor Called as a Function When Object is called as a function rather than as a constructor, it performs a type conversion. 15.2.1.1 Object ( [ value ] ) When the Object function is called with no arguments or with one argument value, the following steps are taken: If value is null, undefined or not supplied, create and return a new Object object exactly as if the standard built-in Object constructor had been called with

What does 'new' keyword mean when used inside an interface in C#?

霸气de小男生 提交于 2019-12-02 20:18:40
Developing an interface generic I wished to declare a constructor in an interface but it says constructors are forbidden there. I've tried to declare a static factory method then, but it says neither static methods are allowed and suggests using 'new' keyword. But I have hardly any idea of what could 'new' keyword exactly mean when used inside an interface in C#. Have you? UPDATE: I didn't post any sample code because I didn't want to mix 2 questions - how to specify a constructor/factory in an interface AND what does the 'new' keyword mean in interfaces. I I even was only forced to specify

Deleting an object in C++

好久不见. 提交于 2019-12-02 20:17:54
Here is a sample code that I have: void test() { Object1 *obj = new Object1(); . . . delete obj; } I run it in Visual Studio, and it crashes at the line with 'delete obj;'. Isn't this the normal way to free the memory associated with an object? I realized that it automatically invokes the destructor... is this normal? Here is a code snippet: if(node->isleaf()) { vector<string> vec = node->L; vec.push_back(node->code); sort(vec.begin(), vec.end()); Mesh* msh = loadLeaves(vec, node->code); Simplification smp(msh); smp.simplifyErrorBased(errorThreshold); int meshFaceCount = msh->faces.size();

Override new operator in C++ while crtdbg.h is causing conflicts

帅比萌擦擦* 提交于 2019-12-02 19:51:22
While trying out some memory tracking and preparation for my own memory manager, I tried to override the new operator. The article on flipcode was my main guideline in this process ( http://www.flipcode.com/archives/How_To_Find_Memory_Leaks.shtml ). After implementing the techniques described in that article, I am left with the problem that somewhere in the STL the "crtdbg.h" is being included either directly or indirectly through some of the header-files that are being included (Using Visual Studio 2010). This results in an error: [...]10.0\vc\include\crtdbg.h(1078): error C2365: 'operator

What is the difference between type and type.__new__ in python?

天涯浪子 提交于 2019-12-02 19:26:00
I was writing a metaclass and accidentally did it like this: class MetaCls(type): def __new__(cls, name, bases, dict): return type(name, bases, dict) ...instead of like this: class MetaCls(type): def __new__(cls, name, bases, dict): return type.__new__(cls, name, bases, dict) What exactly is the difference between these two metaclasses? And more specifically, what caused the first one to not work properly (some classes weren't called into by the metaclass)? In the first example you're creating a whole new class: >>> class MetaA(type): ... def __new__(cls, name, bases, dct): ... print 'MetaA._

C++ STL allocator vs operator new

☆樱花仙子☆ 提交于 2019-12-02 15:38:22
According to C++ Primer 4th edition, page 755, there is a note saying: Modern C++ programs ordinarily ought to use the allocator class to allocate memory. It is safer and more flexible. I don't quite understand this statement. So far all the materials I read teach using new to allocate memory in C++. An example of how vector class utilize allocator is shown in the book. However, I cannot think of other scenarios. Can anyone help to clarify this statement? and give me more examples? When should I use allocator and when to use new ? Thanks! For general programming, yes you should use new and

Can the C++ `new` operator ever throw an exception in real life?

寵の児 提交于 2019-12-02 15:28:01
Can the new operator throw an exception in real life? And if so, do I have any options for handling such an exception apart from killing my application? Update: Do any real-world, new -heavy applications check for failure and recover when there is no memory? See also: How often do you check for an exception in a C++ new instruction? Is it useful to test the return of “new” in C++? Will new return NULL in any case? The new operator, and new[] operator should throw std::bad_alloc , but this is not always the case as the behavior can be sometimes overridden. One can use std::set_new_handler and

Android ListView, start new activity

∥☆過路亽.° 提交于 2019-12-02 15:21:14
问题 Hey can someone tell me how I can start an activity by pressing an item in a listview? Here is a hunch I have: EDIT - I have fixed it i think becuse i get no error messages. but when i will start this activity (Videos) the app carshes and wants to force close whats the problem? help pls :D Here is the source code- package com.alpha.liveshit; import android.app.ListActivity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.ArrayAdapter;

How to add to an existing hash in Ruby

白昼怎懂夜的黑 提交于 2019-12-02 14:07:42
In regards to adding an key => value pair to an existing populated hash in Ruby, I'm in the process of working through Apress' Beginning Ruby and have just finished the hashes chapter. I am trying to find the simplest way to achieve the same results with hashes as this does with arrays: x = [1, 2, 3, 4] x << 5 p x If you have a hash, you can add items to it by referencing them by key: hash = { } hash[:a] = 'a' hash[:a] # => 'a' Here, like [ ] creates an empty array, { } will create a empty hash. Arrays have zero or more elements in a specific order, where elements may be duplicated. Hashes