Top "New-operator" questions

new is a language construct that dynamically allocates memory from free store and initialises the memory using the constructor.

JavaScript: The Good Parts - How to not use `new` at all

Crockford's book, JavaScript: The Good Parts, says (on page 114) that constructor functions should always be given names with an initial …

javascript oop constructor new-operator
Is it okay to manually throw an std::bad_alloc?

I have this code.. CEngineLayer::CEngineLayer(void) { // Incoming creation of layers. Wrapping all of this in a try/catch block …

c++ new-operator throw bad-alloc
Allocating struct with variable length array member

I know I can do new char[n] to create an array of n chars. This works even when n …

c++ new-operator c++11 dynamic-memory-allocation
How do i allocate memory for a 2d array?

How do i declare a 2d array using the 'new' operator? My book says this: int (*p)[4]; p=new[3][4]; but …

c++ arrays new-operator dynamic-arrays
What values can a constructor return to avoid returning this?

What are the exact circumstances for which a return statement in Javascript can return a value other than this when …

javascript constructor new-operator
Does new[] call default constructor in C++?

When I use new[] to create an array of my classes: int count = 10; A *arr = new A[count]; I see …

c++ arrays standards new-operator
How to cleanly initialize attributes in Ruby with new?

class Foo attr_accessor :name, :age, :email, :gender, :height def initalize params @name = params[:name] @age = params[:age] @email = params[:…

ruby object new-operator ruby-1.9.3
ruby on rails, creating new object, use create or new method?

I am trying to create an object via an API, i.e. no forms are required, should I be doing …

ruby-on-rails ruby api new-operator createinstance
add element to ruby array return new array

I would like to add an element to an array but without actually changing that array and instead it returning …

ruby arrays copy new-operator
Is there any guarantee of alignment of address return by C++'s new operation?

Most of experienced programmer knows data alignment is important for program's performance. I have seen some programmer wrote program that …

c++ performance alignment new-operator