> This doesn't work because you don't know who allocated that memory.
I obviously haven't fully fleshed it out (I'm not writing an RFC here), but address re-use would be a consideration as you mention.
> You only "need" it if you've lost track of your memory and have no clue what is allocated and what isn't and you're trying to solve the problem (the wrong way) with these runtime checks.
No, you can do:
char* a = (char*)malloc(/**/);
if(a == NULL) printf("error"); // Never runs
/* Any other checks you want to perform */
/* Some processing later */
a[0] = 'a'; // Crash here
In this case you have done nothing wrong. At the time of requesting memory there was enough space and the kernel said that you could have it. It's only when you come to actually access it did you find that it wasn't really allocated yet and there was no longer enough memory there for it.
> If you're going to change the language anyway (changing what the compiler does), just use C++ with unique_ptrs and they do precisely that without is_alloc.
You don't have to change the way in which the compiler works. You can likely do this with some macros. You would need some way to probe memory allocations though.
> I obviously haven't fully fleshed it out (I'm not writing an RFC here)
Whatever you don't state explicitly is assumed to be like the status quo. You've completely moved the goalposts with each reply.
> No, you can do [...]
Which a simple is_alloc doesn't help with because the allocator doesn't know if the kernel has actually mapped the memory to a physical page.
This requires help from the kernel, which wasn't stated anywhere, nor was this goal stated anywhere.
> You don't have to change the way in which the compiler works. You can likely do this with some macros.
You can't reflect over a struct in C with macros. You can maybe build something that works with some macro hacks that require you to declare each auto-cleaned field with a special macro.
This again is completely different from your previously stated idea that you just declare a struct with raw pointers and the compiler generates the appropriate free() calls.
I obviously haven't fully fleshed it out (I'm not writing an RFC here), but address re-use would be a consideration as you mention.
> You only "need" it if you've lost track of your memory and have no clue what is allocated and what isn't and you're trying to solve the problem (the wrong way) with these runtime checks.
No, you can do:
In this case you have done nothing wrong. At the time of requesting memory there was enough space and the kernel said that you could have it. It's only when you come to actually access it did you find that it wasn't really allocated yet and there was no longer enough memory there for it.> If you're going to change the language anyway (changing what the compiler does), just use C++ with unique_ptrs and they do precisely that without is_alloc.
You don't have to change the way in which the compiler works. You can likely do this with some macros. You would need some way to probe memory allocations though.