4 ms·
This brought memories of that pattern (flyweight?) where the data was stored outside the objects, possibly in an array. An object was instantiated only to hold
by narag 9y ago
This brought memories of that pattern (flyweight?) where the data was stored outside the objects, possibly in an array. An object was instantiated only to hold an index to the array position and allow access. That's dirty cheap!
- manigandham 9y agoIt's still commonly used. The NFX library has Pile which does this well for holding large data: http://nfxlib.com/book/caching/pile.html http://nfxlib.com/book/caching/pile.html https://www.infoq.com/articles/Big-Memory-Part-1 https://www.infoq.com/articles/Big-Memory-Part-1
- Shoothe 9y agoThis pattern was also used by Java and .NET for implementing cheap String.substring calls where all substrings would use the same underlying array with just offsets changed. Unfortunately it turns out that people read entire files into a one big String and then have a reference to just a small piece of it (via substring) marking the big underlying array as reachable for the GC holding a lot of memory for no reason. That's why new implementations of substring always copy:)
- kbsletten 9y agoI know this was changed recently-ish in Java, but I hadn't heard of anybody doing the old substring trick in .NET, do you know when they cut over?
- kkokosa 9y agoThere is a lot of good things going on in .NET Core about this. Here is a good description of Span: http://adamsitnik.com/Span/#slicing-without-managed-heap-allocations http://adamsitnik.com/Span/#slicing-without-managed-heap-all...
- matthewwarren 9y agoAFAIK this trick was never possible in .NET because Substring always 'deep copied' the relevant data into a completely new string
- kevingadd 9y agoRegex's implementation in the standard library used to do this, and I think maybe still does. Bonus points because they leaked a reference to the last string you ran a regex against (????) so if it was big you'd just eat up 50 mb of heap for a while.
- pjmlp 9y agoThat pattern can be done in .NET via native memory allocation (MarshalInterop and SafeHandles). With the latest C# 7.x features will become easier to use it.
- pdpi 9y agoIt's a common pattern — e.g. a lot of C++ libraries have some sort of string piece type.
- jimjimjim 9y agogood old fashion separating data from logic.
- aidenn0 9y agoQPX also stored their database in non-GC space in order to prevent the GC from having to walk it.