Hacker Newsnew | past | comments | ask | show | jobs | submit | arka2147483647's commentslogin

For someone who is not a rust programmer, but would like to keep up to date, can somebody tell me what "Tier 4" is. And why must it be quoted?


Rust has 3 "platform support" tiers (effectively - guaranteed to work, guaranteed to build, supposed to work). However, these are (obviously) defined only for some of the target triples. This project defines "Tier-4" (which is normally not a thing) unstable support for Windows Vista-and-prior


tiers 1-3 are policies[0] for in-tree targets, so by saying tier 4 they mean one implemented in a fork. Though that kind of skips over targets that can get away with just a custom target spec[1] and not modifying the source.

[0] https://doc.rust-lang.org/beta/rustc/target-tier-policy.html [1] https://doc.rust-lang.org/rustc/targets/custom.html


Tier 3 is max official


All the functions mentioned above, even the cpp one, will reserve atleast the number of elements given to resize() or resize_exact(), but may reserve more than that.

After some pondering, and reading the rust documentation, I came to the conclusion that te difference is this: reserve() will grow the underlaying memory area to the next increment, or more than one increment, while reserve_exact() will only grow the underlaying memory area to the next increment, but no more than that.

Eg, if grow strategy is powers of two, and we are at pow(2), then reserve() may skip from pow(2) to pow(4), but reserve_exact() would be constrained to pow(3) as the next increment.

Or so i read the documentation. Hopefully someone can confirm?


> even the cpp one, will reserve atleast the number of elements given

The C++ one, however, will not reserve more than you ask for (in the case that you reserve greater than the current capacity). It's an exact reservation in the rust sense.

> reserve() will grow the underlaying memory area to the next increment, or more than one increment, while reserve_exact() will only grow the underlaying memory area to the next increment, but no more than that

No, not quite. Reserve will request as many increments as it needs, and reserve_exact will request the exact total capacity it needs.

Where the docs get confusing, is that the allocator also has a say here. In either case, if you ask for 21 items, and the allocator decides it prefers to give you a full page of memory that can contain, say, 32 items... then the Vec will use all the capacity returned by the allocator.


As far as I can tell, in the current implementation, reserve_exact is indeed exact. The only situation in which the capacity after calling reserve_exact will not equal length + additional is when it was already greater than that. Even if the allocator gives more than the requested amount of memory, the excess is ignored for the purposes of Vec's capacity: https://github.com/rust-lang/rust/blob/4b57d8154a6a74d2514cd...

Of course, this can change in the future; in particular, the entire allocator API is still unstable and likely won't stabilize any time soon.


Maybe more interestingly, line 659, slightly above that, explains that we know we got [u8] but today the ordinary Rust allocator promises capacity is correct, so we just ignore the length of that slice.

We could, as that comment suggests, check the slice and see if there's enough room for more than our chosen capacity. We could also debug_assert that it's not less room, 'cos the Allocator promised it would be big enough. I dunno if that's worthwhile.


https://en.cppreference.com/w/cpp/container/vector/reserve.h...

says

> Increase the capacity of the vector (the total number of elements that the vector can hold without requiring reallocation) to a value that's greater or equal to new_cap.

I belive that the behaviour of reserve() is implementation defined.


Because there's only a single function here, it has to either be Vec::reserve or Vec::reserve_exact

If you don't offer Vec::reserve_exact then people who needed that run out of RAM and will dub your stdlib garbage. If you don't offer Vec::reserve as we've seen C++ programmers will say "Skill issue" whenever a noob gets awful performance as a result. So, it's an easy choice.


That said MSVC,GCC and clang all implement it to allocate an exact value.


> In either case, if you ask for 21 items, and the allocator decides it prefers to give you a full page of memory that can contain, say, 32 items... then the Vec will use all the capacity returned by the allocator.

It would be nice if this were true but AFAIK the memory allocator interface is busted - Rust inherits the malloc-style from C/C++ which doesn’t permit the allocator to tell the application “you asked for 128 bytes but I gave you an allocation for 256”. The alloc method just returns a naked u8 pointer.


The global allocator GlobalAlloc::alloc method does indeed return a naked pointer

But the (not yet stable) Allocator::allocate returns Result<NonNull<[u8]>, AllocError> --- that is, either a slice of bytes OR a failure.

Vec actually relies on Allocator not GlobalAlloc (it's part of the standard library so it's allowed to use unstable features)

So that interface is allowed to say you asked for 128 bytes but here's 256. Or, more likely, you asked for 940 bytes, but here's 1024. So if you were trying to make a Vec<TwentyByteThing> and Vec::with_capacity(47) it would be practical to adjust this so that when the allocator has 1024 bytes available but not 940 we get back a Vec with capacity 51 not 47.


You misread the documentation. Reserve-exact is precisely that - the growth strategy is ignored and you are ensured that at least that many more elements can be inserted without a reallocation. Eg reserve_exact(100) on an empty Vec allocates space for 100 elements.

By contrast reserve will allocate space for the extra elements following the growth strategy. If you reserve(100) on an empty Vec the allocation will be able to actually insert 128 (assuming the growth strategy is pow(n))


Actually that's not quite correct.

Vec::reserve(100) on an empty Vec will give you capacity 100, not 128 even though our amortization is indeed doubling.

The rules go roughly like this, suppose length is L, present capacity is C, reserve(N):

1. L + N < C ? Enough capacity already, we're done, return

2. L + N <= C * 2 ? Ordinary doubling, grow to capacity C * 2

3. Otherwise, try to grow to L + N

This means we can grow any amount more quickly than the amortized growth strategy or at the same speed - but never less quickly. We can go 100, 250, 600, 1300 and we can go 100, 200, 400, 800, 1600 - but we can''t do 100, 150, 200, 250, 300, 350, 400, 450, 500...


Honestly, i doubt it. That exposes many details to the programmers that many of them would prefer not to know.

The higher level the language, the less interest there is to manually manage memory. It is just something to offload to the gc/runtime/etc.

So, i think this is a no-go. The market wont accept it.


You already don’t have a choice. The reason we are all in the cloud is that hardware stopped scaling properly vertically and had to scale horizontally, and we needed abstractions that kept us from going insane doing that.

If you really want to dumb down what I’m suggesting, it’s is tantamount to blade servers with a better backplane, treating the box as a single machine instead of a cluster. If IPC replaces a lot of the RPC, you kick the Amdahl’s Law can down the road at least a couple of process cycles before we have to think of more clever things to do.

We didn’t have any of the right tooling in place fifteen years ago when this problem first started to be unavoidable, but is now within reach, if not in fact extant.


It's tricky to decode all this but there are a lot of misconceptions.

First, amdahl's law just says that the non parallel parts of a program become more of a bottleneck as the parallel parts are split up more. It's trivial and obvious, it has nothing to do with being able to scale to more cores because it has nothing to do with how much can be parallelized.

Second in your other comment, there is nothing special about "rust having the semantics" for NUMA. People have been programming NUMA machines since they existed (obviously). NUMA just means that some memory addresses are local and some are not local. If you want things to be fast you need to use the addresses that are local as much as possible.


You don't need every programmer to leverage the architecture for the market to accept it, just a few that hyper-optimize an implementation to a highly valuable problem (e.g., ads or something like that).


QuickShell - it should be called


Quicshell*


QSH?


At least that isn’t an existing ham radio Q-code!


That's already a project (library for building a desktop environment).


I think you would find it very difficult to find even a single game which has done this.


Seems to me, that to some Linux has come to mean all things Unix-ly


Yes it seems to be misused that wat - now just try to rerun scripts on macOS or BSD when the author thinks Linux is all there is.


That's usually caused by assuming that everything is bash, which is not true even for Linux.


While that may certainly arise if someone is lazy about #!/bin/sh when they didn't really mean /bin/sh I'd bet it's /bin/sed and similar friends that are different between the GNU versions and the BSD versions. So much make-macro-trickery out there when one is trying to use -i without a backup suffix, and I have no idea why GNU tried to be a trailblazer with their parsing :(


Yes - I come from an era when I used multiple Unixes and for several of them default shell was (t)csh.

Don't assume anything in shells except POSIX sh.

Unfortunately there are people who think Linux is the only way.


The article mentions ANSI-C at places. So seems like the old c standard is targeted.


Respectfully, the value of a c++ wrapper/implementation comes from the fact that it behaves like one would expect a C++ classes to behave. That is, RAII, and so on.

If the underlying resource can not behave like a class, it would be better to expose a free function style api, eg:

    Handle h = ResourceGet();
    ResourceDoSomething(h);
    h.release();


Why does sp::primitive_array<> even exist?

Should it not be std::array<>?


This is really not the same thing at all.

sp::primitive_array holds memory following the Arrow specification, which can be operated upon in place from e.g. ArrowCpp, PyArrow, etc.


You can actually do it both ways, but which is easiest for whom is different.


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: