3 ms·
What is the meaning of the word “boxed” in this article? Bit confused about it.
by stephantul 2y ago
What is the meaning of the word “boxed” in this article? Bit confused about it.
- masklinn 2y agoUsually it's used for saying something is heap allocated. In this case it doesn't seem very relevant, it looks like the article just assumes boxed records are dynamically or structurally typed, even though that's completely unrelated.
- mostlylurks 2y agoNot represented directly in memory in its raw form right where the value is placed, but rather stored somewhere else (usually the heap) / in an opaque manner and accessed via an indirection, such as a pointer / reference. Often involved in making things polymorphic, because different types usually have different representations in memory even if they implement the same interface, so they need to be boxed.
- tialaramex 2y agoIf you're familiar with Rust it's what's different about Box<T> compared to T, if you know Java, all their "objects" are boxed it's the difference between Integer and the primitive int type. In C++ it's approximately std::unique_ptr<T> in a lot of the high level languages (indeed Java I mentioned above fits this if you're not familiar with the details) boxing is silently done for you and you are unaware of it unless you care about fine details. Think of an arbitrary type Goose, where "is" the Goose? Assume for a moment there's data associated so the Goose does need to be stored somewhere, the two usual candidates are "the stack" and "the heap". If you've no idea what those are then I'm afraid you need a bit more CS to really engage with this conversation. Boxing puts things on the heap, typically with just a pointer to that box kept on the stack.
- DeathArrow 2y agoBoxing means transforming a variable of a value type into a variable of reference type. //boxing var a = 5; //int, value type string b = (string)a; //string, reference type Unboxing is the reverse process of transforming variables of reference types to value types. A value type variable holds the value directly, while a reference type variable holds a reference that points to a memory address where the actual value is found.
- kragen 2y agoThis is true in some circumstances but not in general. Consider how integers are represented in Emacs Lisp, OCaml, or Smalltalk. They're unboxed, but boxing them like CPython does wouldn't change their semantics, so it doesn't seem correct to say that it would change their type. And there's no way in the language to box them. Fundamentally, boxing is a question about implementation, not semantics. I think a more generally correct statement would be: > An unboxed value can be held in CPU registers directly, while a boxed value is referenced through a memory address where the actual value is found.
- SideburnsOfDoom 2y ago> Boxing is the process of converting a value type (on the stack, passed by value) to the type "object". When the runtime boxes a value type, it wraps the value inside a object instance and stores it on the managed heap (passed by reference). Unboxing extracts the value type from the object. https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/types/boxing-and-unboxing https://learn.microsoft.com/en-us/dotnet/csharp/programming-...