new

delete[] an array of objects

Hello I have allocated and array of Objects Objects *array = new Objects[N]; How should I delete this array? Just delete[] array; or with iterating over the array's elements? for(int i=0;i<N;i++) delete array[i]; delete[]; Thanks UPDATE: I changed loop body as delete &array[i]; to force the code to compile. ...

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

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 instructio...

Passing arguments to objects created using the new operator?

Hi guys, I have a small C++ problem to which I don't know the best solution. I have two classes A and B as follows: class A { int n; B* b; public: A(int num): n(num) { b = new B[n]; for (int i = 0; i < n; i++) { b[i].setRef(this); } } ~A() { delete [] b; } }; class...

What's the outcome if I use free with new or delete with malloc?

It is a compiler error or runtime error? The code below can be compiled! class Base{ void g(); void h(); }; int main() { Base* p = new Base(); free(p); return 0; } However it can't be compiled with a virtual function if I declare the class Base like this class Base{ virtual void g(); void h(); }; The code below can be co...

linux new/delete, malloc/free large memory blocks

Hi folks, We have a linux system (kubuntu 7.10) that runs a number of CORBA Server processes. The server software uses glibc libraries for memory allocation. The linux PC has 4G physical memory. Swap is disabled for speed reasons. Upon receiving a request to process data, one of the server processes allocates a large data buffer (usin...

Reallocating memory via "new" in C++

Quick question regarding memory management in C++ If I do the following operation: pointer = new char [strlen(someinput_input)+1]; And then perform it again, with perhaps a different result being returned from strlen(someinput_input). Does this result in memory being left allocated from the previous "new" statement? IE, is each new ...

What is the difference between these usages: new SubElement() and SubElement()?

Into a class constructor, I need to create some objects on the fly and add them to a vector. Here is my code: ContainerClass::ContainerClass() { for (int i = 0; i < limit; i++) elements.push_back(SubElement()); } Is this the same thing with new SubElement()? Do I still need to free those SubElement() objects into the Containe...

Why new()/delete() is slower than malloc()/free()?

Why new()/delete() is slower than malloc()/free()? EDIT: Thanks for the answers so far. Please kindly point out specifications of standard C++ implementation of new() and delete() if you have them thanks! ...

how to add new language search to advanced search page in moss 2007 through code?

In Moss 2007 how to add japanese,portuguese,romanian languages through code.we can edit the xml and add the particular lcid for achieving the same.but how to make it through code.Please help. ...

Problems with classes (super new)

Hi, I've problems to figure it out what's happening in the following exercise, I'm learning Smalltalk, so I'm newbie. Class A>>new ^super new initialize. A>>initialize a:=0. Class B>>new: aParameter |instance| instance := super new. instance b: instance a + aParameter. ^instance B>>initialize b:=0. The problem says wha...

Hi, I want to create new DOCX file by reading DOCX template (it's content is already replaced)

Up to now code is read the template and replace with new values and finally replace the docx file with new values. Can any one please tell me how to save the replaced docx file in diffrent name?. My code is bellow. using (WordprocessingDocument wordDoc = WordprocessingDocument.Open(document, true)) { string docTe...

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

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 b...

How to callback the new list id jQuery UI: sortable

Hi, I'm trying to use the sortable widget for my site. I have a mini scheduling app that I'd like to display a list of appointments for the week sorted by days. For this example we'll use only two days ( 2 lists ). If I wanted to drag an appointment (list item) from day 2 over to day 1, is there a way I can callback the id of list 1 a...

How to Edit or Add a New Row in jqGrid

My jqGrid that does a great job of pulling data from my database, but I'm having trouble understanding how the Add New Row functionality works. Right now, I'm able to edit inline data, but I'm not able to create a new row using the Modal Box. I'm missing that extra logic that says, "If this is a new row, post this to the server side UR...

IPhone sdk accelerometer delegate question

in my app the accelerometer lags. a lot. i think it might be to do with the fact that all of my code is running through my main . h file which is also the accelerometer delegate like this: @interface MainView : UIView <UIAccelerometerDelegate> { IBOutlet UISlider *sensitivity; float valueX; CGPoint pos; NSTimer *maintimer; NSTimer ...

Dynamic array of template objects in C++

#include <vector> using namespace std; int main() { vector<int> *list = new vector<int>[33]; delete[] list; return 0; } Any reason why the delete SIGSEGVs? ...

inheritance from str or int

Why I have problem creating a class the inherite from str (or also int) class C(str): def __init__(self, a, b): str.__init__(self,a) self.b = b C("a", "B") TypeError: str() takes at most 1 argument (2 given) tha same happens if I try to use int instead of str, but it works with custom classes. I need to use __new__ inst...

C# memory allocation

Does using operator new in c# might fail (if it requires a large memory for example)? -Solved- And how to discover it? -Solved- What other failures new operator might throw? Thanks ...

Using "Object.create" instead of "new"

Javascript 1.9.3 / ECMAScript 5 introduces Object.create, which Douglas Crockford amongst others has been advocating for a long time. How do I replace new in the code below with Object.create? var UserA = function(nameParam) { this.id = MY_GLOBAL.nextId(); this.name = nameParam; } UserA.prototype.sayHello = function() { cons...

call parent constructor in ruby

Hi! How can I call parents constructor ? module C attr_accessor :c, :cc def initialization c, cc @c, @cc = c, cc end end class B attr_accessor :b, :bb def initialization b, bb @b, @bb = b, bb end end class A < B include C attr_accessor :a, :aa def initialization (a, b, c, aa, bb, ...