new

C++ new int[0] -- will it allocate memory?

A simple test app: cout << new int[0] << endl; outputs: 0x876c0b8 So it looks like it works. What does the standard say about this? Is it always legal to "allocate" empty block of memory? ...

based on what logical reasons, virtual and new modifiers have diffrent results in inheritance and polymorphism issues?

Hi ... I know that when we have a virtual function in our own base class, then by overriding it in a derived class and considering casting when variable declaration, we have different result with comparison to using new modifier in the derived class. but why? Is there any logical reason for that or we have to learn it without any reason?...

Practical usage of new (modifier) functions?

Hi... What's the Practical usage of new (modifier) functions? ...

Should we assert every object creation in java?

Sounds like a stupid question with an obvious answer :) Still I've ventured to ask just be doubly sure. We are indeed using asserts like given below ArrayList alProperties = new ArrayList(); assert alProperties != null : "alProperties is null"; Problem is that making a small & simple document to follow, on asserts is difficult. Th...

C++: Call destructor and then constructor (resetting an object)

Hi. I want to reset an object. Can I do it in following way? anObject->~AnObject(); anObject = new(anObject) AnObject(); // edit: this is not allowed: anObject->AnObject(); This code is obviously a subset of typical life cycle of an object allocated by in placement new: AnObject* anObject = malloc(sizeof(AnObject)); anObject = new (a...

'new' modifier in Java

Is there an equivalent to C#'s 'new' modifier in Java? I'd like to use it for unit tests - every init() method should be marked final and annotated with @Before. Then, jUnit executes all of these init() methods. I don't want to bother coming up with new names for each of these init() methods, and I definitely wants to mark them as fina...

С++: memory leaks

Sorry for my English. The question: At what value of variable n the following code will cause memory leaks? That's the code: int* Bar(int n) { if (n == 1) throw "exception"; return new int[n]; } void Foo(int n) { int *a = Bar(n); if (n <= 2) return; delete[] a; } It's clear that if n is 2 there will be memory le...

ExtJS display link in new tab

Hello, I am using ExtJS version 2. I am clicking a button to add new tab to a TabPanel. The new tab function looks like this: function addTab(tabTitle, targetUrl){ tabPanel.add({ title: tabTitle, iconCls: 'tabs', closable:true }).show(); } I would like to know if it's possible to get the targetU...

Any reason to overload global new and delete?

Unless you're programming parts of an OS or an embedded system are there any reasons to do so? I can imagine that for some particular classes that are created and destroyed frequently overloading memory management functions or introducing a pool of objects might lower the overhead, but doing these things globally?? Addition I've just fo...

.NET Placement New

Is there a placement new in .NET (like C++)? In other words if I allocate some memory in VB.NET Dim Foo(64) as Byte I want to instance BarClass in the Foo memory (something like...) Dim Bar as New BarClass(Foo) However, I don't see any syntax to do this. Instead I have to do something like: Dim Foo(1) as BarClass Foo(0) = new...

Having a problem with placement-new!

I am having a problem placing an instance of my reference-counting Pointer<Type> class into my Array class. Using the debugger, it seems that the constructor is never called (which messes up the reference-count and causes a segfault down the line)! My push_back function is: void push_back(const T& element) { if (length >= max) reall...

Memory Allocation Crash

I have stumbled accross a strange problem in which I cannot understand. I am not an expert at C/C++ so bear with me. I have an NPC class, which derives from a Player class, which derives from a Sprite class. The sprite class contains a setupAnimation function, which allocates an array of floats containing coordinates on the texture, each...

svn / subversion: Get ALL files on new check out, but then exclude certain files from update/check in

After a fresh checkout, I want to get ALL files, specifically this file: etc/config.ini However, once I modify etc/config.ini, I do not want it committed with "svn commit ..." nor should it be reverted on a "svn up". This would allow you to get default values on an initial checkout (convention over configuration), but then after config...

Tutorial: Add another screen (credits) without adding a subview?

Any help to the above title would be so helpful. I have an app that I am working on that currently has a tab bar that delegates you to go to a. page 1 or b. page 3, with the tab bar being an invisible page 2... I need to add a credits button to p.3 but every tutorial I see is how to add it with a subview. I can not do this because of ...

What effect does the "new" keyword have in C# and why is it only a warning when not employed?

Consider the following code: public abstract class Test1 { public object Data { get; set; } } public abstract class Test2<T> : Test1 { public T Data { get; set; } } This will generate the following warning: 'Test2.Data' hides inherited member 'Test1.Data'. Use the new keyword if hiding was intended. Why is this only a w...

How would you replace the 'new' keyword?

There was an article i found long ago (i cant find it ATM) which states reasons why the new keyword in C++ is bad. I cant remember all of the reasons but the two i remember most is you must match new with delete, new[] with delete[] and you cannot use #define with new as you could with malloc. I am designing a language so i like to ask ...

Policy with catching std::bad_alloc

So I use Qt a lot with my development and love it. The usual design pattern with Qt objects is to allocate them using new. Pretty much all of the examples (especially code generated by the Qt designer) do absolutely no checking for the std::bad_alloc exception. Since the objects allocated (usually widgets and such) are small this is har...

using class specific set_new_handler.

For class specific new_handler implementation, i came across the following example in book "effective c++". This looks problem in multithreaded environment, My Question is how to achieve class specific new_handler in multithreaded environment? void * X::operator new(size_t size) { new_handler globalHandler = // insta...

What to do in class specific version of placement new ?

Class-specific version of placement new can be provided even though you can't replace the global one. What scenarios exist where a class should provide its own placement new operator? Even if my class don't implement placement new the following code works (assuming for abc no operator new is overloaded). char arr[100]; abc *pt = n...

Open external link in a new window in ruby docs (rdoc)

Hi there, I'm stuck: I need to create an external link using Rdoc which opens in a new window. What I have and what opens up in the current window is this: ... to be found here[link:../../bla_bla_bla/index.html] ... How do I make it open in a new window? Any idea? Thanks Matt ...