Questions tagged [initialization]

Initialization deals with the task of initializing the contents of your data structure. It's a common practice in statically-typed languages.

Initialization deals with the task of initializing the contents of data structures. This is the initialization of an object, structure, blob of data, or any entity which contains state that must be prepared prior to usage of the entity.

11649 questions
6
votes
2 answers

Is there any benefit to unsetting an array before redeclaring it?

In your opinion, if I had an array of 100 000 entries of 8-character strings, would it be better for memory usage to unset($array) first and then redeclare it as $array = []; or to just directly redeclare it ($array = [];)? Thanks!
Anriëtte Myburgh
  • 13,347
  • 11
  • 51
  • 72
6
votes
3 answers

In C, is it ever O.K. to increment an uninitialized int?

According to this SO answer, incrementing an uninitialized int in C results in undefined behavior. But what if I don't care at all about the initial value; for example, what if I just want an incrementing id? Is this dangerous or bad practice for…
jds
  • 7,910
  • 11
  • 63
  • 101
6
votes
2 answers

How to find global static initializations

I just read this excellent article: http://neugierig.org/software/chromium/notes/2011/08/static-initializers.html and then I tried: https://gcc.gnu.org/onlinedocs/gccint/Initialization.html What it says about finding initializers does not work for…
milianw
  • 5,164
  • 2
  • 37
  • 41
6
votes
1 answer

In perl, can HEREIS notation be used inside hash initialization?

I am trying to initialize a hash like this: use strict; my %hash = ( key => < 17 ); When I run perl -cw on this code, I get the error 'syntax error at hash-initialize-test.pl line 5, near ";"'. Is…
David Levner
  • 341
  • 1
  • 8
6
votes
2 answers

Vector of object containing uninitialized value

Does this code cause undefined behaviour: #include struct S { S() {} int x; }; int main() { std::vector vec(5, S()); } Since S() default-initializes an automatic object, its contents are not zeroed first, so x would be…
M.M
  • 138,810
  • 21
  • 208
  • 365
6
votes
6 answers

How do I call CMSampleBufferGetAudioBufferListWithRetainedBlockBuffer?

I'm trying to figure out how to call this AVFoundation function in Swift. I've spent a ton of time fiddling with declarations and syntax, and got this far. The compiler is mostly happy, but I'm left with one last quandary. public func…
nhgrif
  • 61,578
  • 25
  • 134
  • 173
6
votes
1 answer

gcc and clang both elide the call to the move constructor in the snippet below. Is this correct?

In the code below an object s of class S is used to initialize an object of class D with a direct-initialization D d(s);. The conversion function S::operator D() is used to convert the object s into a temporary object of type D. Then, gcc and clang…
Belloc
  • 6,318
  • 3
  • 22
  • 52
6
votes
6 answers

What is the purpose of the init! failable initializer?

The Apple Swift Programming Language guide mentions the existence of the init! initializer, but does not provide any example for it. (Search for init! in this page) I understand the use of a normal failable initializer declared with init?, but I…
6
votes
1 answer

Error in Swift class: Property not initialized at super.init call - How to initialize properties which need use of self in their initializer parameter

I am overriding a UITableViewController in swift, in which I have two required variables which are initialized by using a weak reference of self since these are used to implement UITableViewDataSource protocol and need self reference to use its…
iMemon
  • 1,095
  • 1
  • 12
  • 21
6
votes
1 answer

C++ Constexpr member of template type

I want to create a template class with a member which is a constexpr array. The array needs, of course, a different initialization depending on the type it is but I cannot declare the array without initializing it. The problem is that I don't know…
barsdeveloper
  • 930
  • 8
  • 28
6
votes
1 answer

Why Initializing References to Null Is allowed In Java?

In the following example that uses JDBC (this question though is not specific to JDBC): Connection conn = null; try { ..... Do the normal JDBC thing here .... } catch(SQLException se) { if(conn != null) { conn.close(); } } If I do…
davison
  • 335
  • 1
  • 3
  • 16
6
votes
1 answer

error on g++ 4.8.2 at list method-argument default initialization

I am trying the new features of c++11 and I found an issue. This is my code: #include #include #include using namespace std; class A { public: int f (list a, list b={}) { cout…
Eze Velez
  • 351
  • 1
  • 2
  • 6
6
votes
3 answers

Spring Boot - inject map from application.yml

I use spring boot in a J2SE app. I have some constant data, such as a map, indicating a HandlerClass to process one operation Type. The map relation is not changed, so I want to config it in application.yml I try this: info: modify_nodeip:…
NingLee
  • 1,477
  • 2
  • 17
  • 26
6
votes
1 answer

How do I initialize a Set in Java?

This is fine... public class someClass { private Set pre; public void someMethod() { pre.add(new Element()); } } But this isn't... public class someClass { public void someMethod() { Set pre; …
Micromancer
  • 81
  • 1
  • 1
  • 4
6
votes
2 answers

Handle UIView common initialization in swift

Some special classes like UIView have more than one designated initializer. In Objective-X, we could factor common initialization into a separate function - (id)initWithCoder:(NSCoder *)aDecoder { if (self = [super initWithCoder:aDecoder]) { …
graveley
  • 311
  • 3
  • 5