boxing Questions

6

Solved

Boxing converts a value type to an object type. Or as MSDN puts it, boxing is an "operation to wrap the struct inside a reference type object on the managed heap." But if you try to drill into tha...
Speedwriting asked 12/9, 2011 at 15:4

1

Solved

Consider the following class: package test class Test { def main(args: Array[String]): Unit = { val i: Int = 0 println(i) } } The bytecode of main is: public main([Ljava/lang/String;)V // ...
Trillbee asked 7/11, 2017 at 11:15

4

I recently came across this Stackoverflow question: When to use struct? In it, it had an answer that said something a bit profound: In addition, realize that when a struct implements an interfa...
Gymnosperm asked 4/3, 2013 at 17:21

1

Solved

In C#, there are structs and classes. Structs are usually (i.e. there are exceptions) stack allocated and classes are always heap allocated. Class instances, therefore, put pressure on the GC and a...
Saimon asked 11/8, 2017 at 12:13

1

Solved

While doing some profiling on one of our applications, I found this code: public TOut GetValue<TIn, TOut>(Func<TIn> getter) { var value = getter(); // Do some stuff with the value ...
Hornstein asked 4/8, 2017 at 12:53

3

Solved

Please help me understand this piece of code in the kotlin docs:- val a: Int = 10000 print(a === a) // Prints 'true' val boxedA: Int? = a val anotherBoxedA: Int? = a print(boxedA === anotherBoxedA...
Distiller asked 17/7, 2017 at 8:30

1

Solved

The Perl 6 docs list a bunch of types. Some of them, such as Str, have more complicated box/unbox behaviors. Is it possible to define my own type, specifying my own routines for the box/unboxing? ...
Concordia asked 6/5, 2017 at 14:10

3

Solved

Do boxing and unboxing has the same performance hit? Or is unboxing faster, let's say? (If yes, can you briefly explain the main reason.)
Fluff asked 4/3, 2012 at 12:56

2

Solved

class C<T> where T : struct { bool M1(object o) => o is T; bool M2(object o) => o is T?; } The two methods above seems to behave equally, both when passing null reference or boxed T...
Nostomania asked 7/3, 2017 at 0:14

5

Solved

Integer i = null; if (i == 3) Why the second line above throws a NullPointerException, IMHO, this has only one meaning which is Wrapper Object i is to be unboxed which yields the Exception such a...
Prerecord asked 7/2, 2012 at 14:1

2

Solved

This code is shown in The Rust Programming Language: #![feature(box_syntax, box_patterns)] fn main() { let b = Some(box 5); match b { Some(box n) if n < 0 => { println!("Box contains ne...
Capitulate asked 11/2, 2017 at 14:50

1

Solved

I am asking this for performance sake - using lots of boxing makes lots of heap allocations which brings more GC collects which sometimes causes apps to freeze for a glimpse which annoy users.
Locker asked 19/10, 2016 at 14:8

1

Solved

What is the nice and working way of doing a cast like this? seq { yield (box "key", box "val") } |> Seq.cast<string*string> Since this looks extremely ugly: seq { yield (box "key", box...
Footlocker asked 27/7, 2016 at 13:42

3

Solved

I have some non-copyable type and a function that consumes and (maybe) produces it: type Foo = Vec<u8>; fn quux(_: Foo) -> Option<Foo> { Some(Vec::new()) } Now consider a type t...
Nameplate asked 15/7, 2016 at 13:17

2

Solved

When unboxing takes place there is the copy of boxed value into an appropriate variable type but what happens at the memory location of the boxed copy on heap. Is boxed copy remain at that location...
Leban asked 27/5, 2016 at 16:49

3

Solved

I'm new to programming, As per MSDN, Boxing is the process of converting a value type to the type object or to any interface type implemented by this value type. When the CLR boxes a value type...
Correll asked 22/5, 2016 at 6:22

4

Solved

I have a piece of code which I need to understand: public static void main(String[] args) { Character c = new Character('a'); Character cy = new Character('a'); char cx = 'a'; System.out.prin...
Manslaughter asked 11/4, 2016 at 9:2

3

Solved

I am sure my question doesn't make sense, but it's because I don't know what I am seeing or how to describe it... The following code compiles fine, but it shouldn't because int is not the same ty...
Pickaxe asked 2/3, 2016 at 7:45

2

Solved

I'm wondering how you could compare two boxed integers (either can be signed or unsigned) to each other for equality. For instance, take a look at this scenario: // case #1 object int1 = (int)50...
Disparity asked 26/1, 2016 at 6:48

1

Solved

Say I have the following code: Map<String, Boolean> map = ... map.put("foo", true); Theoretically, true will have to be autoboxed, resulting in a slight performance hit versus inserting Bo...
Pseudohermaphroditism asked 8/1, 2016 at 23:8

4

Solved

What is the difference between Boxing and AutoBoxing in Java? Several Java Certification books use two such terms. Do they refer to the same thing that is Boxing?
Amend asked 24/11, 2015 at 14:4

4

I'm comparing two pieces of code Integer x = new Integer(0), y; y=x; x+=0; System.out.println(x==y); // prints false And Integer x = 0, y; y=x; x+=0; System.out.println(x==y); // prints true ...
Calvados asked 24/11, 2015 at 8:35

1

Solved

I'm currently trying to convert an Expression<Func<T,object>> to an Expression<Func<T,bool>> Currently the watch shows me that my expression holds Expression<Fu...
Saprogenic asked 17/11, 2015 at 9:38

6

Solved

Very simple question: int a = 5; string str = a.ToString(); Since ToString is a virtual method of System.Object, does it mean that everytime I call this method for integer types, a boxing occurs...
Carlsbad asked 25/11, 2014 at 16:37

1

Solved

As per the C# specs, is there any guarantee that foo.Bar would have the same effect of being atomic (i.e. reading foo.Bar from different threads would never see a partially updated struct when writ...
Cousteau asked 23/9, 2015 at 0:3

© 2022 - 2024 — McMap. All rights reserved.