Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does new(3) mean?

SelectInst *Sel = new(3) SelectInst(C, S1, S2, NameStr, InsertBefore);

What's the meaning of the new operator here?

What's the meaning of the number 3 after the new operator?

like image 504
John Smith Avatar asked May 03 '17 07:05

John Smith


People also ask

What is the highest news score?

The total possible score ranges from 0 to 20. The higher the score the greater the clinical risk. Higher scores indicate the need for escalation, medical review and possible clinical intervention and more intensive monitoring (see table one).

What are the three elements to clinical response?

Early detection, timeliness and competency of clinical response are a triad of determinants of clinical outcome in people with acute illness.

Why do we use NEWS2?

The technology. The National Early Warning Score (NEWS2) is a system for scoring the physiological measurements that are routinely recorded at the patient's bedside. Its purpose is to identify acutely ill patients, including those with sepsis, in hospitals in England.

What is the difference between NEWS and NEWS2?

Care Quality Improvement DirectorateNEWS2 is the latest version of the National Early Warning Score (NEWS), first produced in 2012 and updated in December 2017, which advocates a system to standardise the assessment and response to acute illness.


1 Answers

This code comes from LLVM's codebase. There's a custom operator new in scope and it is being used to placement-new initialize the objects (cfr. placement syntax)

void *User::operator new(size_t Size, unsigned Us) {
  return allocateFixedOperandUser(Size, Us, 0);
}

Here's a toy example:

class SelectInst
{
public:
  int x;
};

void *operator new(size_t Size, unsigned Us) {
                                ^^^^^^^^^^^ 3 is passed here
                   ^^^^^^^^^^^ allocation size requested

  return ... // Allocates enough space for Size and for Us uses
}

SelectInst *Create() {
  return new(3) SelectInst();
}

int main()
{
  auto ptr = Create();
  return 0;
}

Live Example

Specifically that code is being used to adjust the allocated space to fit additional data.

like image 65
Marco A. Avatar answered Sep 28 '22 12:09

Marco A.