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? ...
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? ...
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?...
Hi... What's the Practical usage of new (modifier) functions? ...
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...
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...
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...
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...
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...
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...
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...
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...
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...
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...
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 ...
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...
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 ...
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...
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...
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...
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 ...