Y
HN Search
Hacker News Search
new
|
comments
|
top
|
jobs
lerno
searching PlanetScale…
1.
▲
2.
▲
3.
▲
4.
▲
5.
▲
6.
▲
10 ms
·
91.
▲
by
lerno
1y ago
You lost me there I'm afraid.
92.
▲
by
lerno
1y ago
Not possible to nest and possible to run down out of stack memory quickly. That said, C3 has a `@stack_mem(1024; Allocator mem) { ... }` which allows to allocate a part of the stack and use that as an allocator with fallback.
93.
▲
by
lerno
1y ago
> You can claim that C3 does not aim to solve memory safety for these reasons, _and they can be understandable_, This seems to be where we speak past each other. What the blog post talks is how C3 handles the problem of memory lifetimes
94.
▲
by
lerno
1y ago
It doesn't zero on free, that's not what the code does. But if you're looking for something to prevent exploits, then no, this is not it, nor does it try to be. How would you want that implemented?
95.
▲
by
lerno
1y ago
Well, we've already tried that, and no one used it.
96.
▲
by
lerno
1y ago
It is a problem for manual memory management. I am not quite sure where you're coming from. In Modern C++ this is managed by RAII, but if you instead look at C there is no solution that doesn't involve various additional code. You
97.
▲
by
lerno
1y ago
> So the issue is clearly not solved. You can use --sanitize=address to get this today, or use the Vmem-based temp allocator (which is only in the 0.7.4 prerelease and only for 64 bit POSIX) if you're curious how it feels and works
98.
▲
by
lerno
1y ago
> The article makes no mention of this, so in the context of the article the title remains very wrong The temp allocator implementation isn't guaranteed to detect it, and the article doesn't go into implementation details and g
99.
▲
by
lerno
1y ago
> care more about binary size than speed That does not seem to be true if you look at how string formatting is implemented.
100.
▲
by
lerno
1y ago
Memory safety as in the full toolset that Rust provides? C3 clearly doesn't, I fully agree.
101.
▲
by
lerno
1y ago
Well, the title (which is poorly worded as has been pointed out) refers to C3 being able to implement good handling of lifetimes for temporary allocations by baking it into the stdlib. And so it doesn't need to reach for any additional
102.
▲
by
lerno
1y ago
No, that is quite possible. You will not be able to use that memory you just returned though. What actually happens is an implementation issue, but it ranges from having the memory overwritten (but still being writable) on platforms with th
103.
▲
by
lerno
1y ago
This is about tracking allocated memory, which is different. I know V claimed it could solve this with static analysis, but in practice it didn't work and had to fallback to a GC. This is true for all similar schemes, that they have so
104.
▲
by
lerno
1y ago
Well the latter is covered: you can make temp allocations out of order when having nested "@pool"s. There are examples in the blog post. It doesn't solve the case when lifetimes are indeterminate. But often they are well know
105.
▲
by
lerno
1y ago
You can certainly do it with RAII. However, what if a language lacks RAII because it prioritizes explicit code execution? Or simply want to retain simple C semantics? Because that is the context. It is the constraint that C3, C, Odin, Zig e
106.
▲
by
lerno
1y ago
Well, there are no objects, no constructors and no destructors.
107.
▲
by
lerno
1y ago
I would say that the title is easily misread. If you open the blog post and just read the title and a few lines into the intro, I think it's clear it's about C3 not having to implement any recently popular language features in ord
108.
▲
by
lerno
1y ago
NSAutoreleasePool keeps a list of autoreleased objects, that are given a "release" message when the pool goes out of scope. `@pool` flushes the temp allocator and all allocations made by the temp allocator are freed when the pool
109.
▲
by
lerno
1y ago
No, I don't think they do. Given a function `foo` that is allocating an object "o" and returns it to the upper scope, how would you do "escape analysis" to determine it should be freed and HOW it should be freed? Wh
110.
▲
by
lerno
1y ago
The benefit is that it: (a) works in a language without RAII, and C-like languages usually does not have that (b) there are no individual heap allocations and frees (c) allocations are grouped together.
111.
▲
by
lerno
1y ago
I am not sure how this would be a problem. Certainly the resource manager should manage the memory itself in some manner. It has very little to do with trying to manage temporary memory lifetimes.
112.
▲
by
lerno
1y ago
Imagine we have a function "foo" which returns an allocated object Bar, we want to pass this to a function "bar" and then have it released. Now we usually cannot do "bar(foo())" because it then leaks. We could
113.
▲
by
lerno
1y ago
A dangling pointer will generally still possible to dereference (this is an implementation detail, that might get improved – temp allocators aren't using virtual memory on supporting platforms yet), but in safe more that data will be s
114.
▲
C3 solved memory lifetimes with scopes
(c3-lang.org)
143 points
by
lerno
1y ago
|
159 comments
115.
▲
by
lerno
1y ago
C3 is a C-like programming language seeking to evolve from C. The 0.7.3 release doesn't have any major changes, but ends up with some gradual improvements such as: - type / typeid equivalence: it's possible to use a constant
116.
▲
by
lerno
1y ago
Something you somewhat touch upon: early adopters are invested in the success of their chosen language because they are relying on its success to make their investment in early adoption pay off. If you are an early adopter of language X and
117.
▲
by
lerno
1y ago
In this case, how would you prevent the user from seeing an invalid foo_vec before initialization? This is either "oh, it's in an illegal state", in which case it's just an annotation without deeper enforcement or you ne
118.
▲
by
lerno
1y ago
A C backend is planned.
119.
▲
by
lerno
1y ago
C++ is just slow to compile. With the standard library it is much worse. The problem is that with C++ you're not getting as much encapsulation as you would in C unless you do extra work that also has a performance hit (pimpl). This mea
120.
▲
by
lerno
1y ago
Jai has operator overloading yes.
More ›