Thread overview | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
October 09, 2012 bigger then size_t | ||||
---|---|---|---|---|
| ||||
What happens when args[1].length is bigger then size_t? Can I detect this? |
October 09, 2012 Re: bigger then size_t | ||||
---|---|---|---|---|
| ||||
Posted in reply to maarten van damme | On 09-Oct-12 18:46, maarten van damme wrote: > What happens when args[1].length is bigger then size_t? > Can I detect this? > Then size_t.max? It can't as it has type size_t. Equal or even close? Nope. As it there would not be enough of even _virtual_ memory to fit array of size_t.max and something else (like your program :)) -- Dmitry Olshansky |
October 09, 2012 Re: bigger then size_t | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dmitry Olshansky | But doesn't args[1] get filled by the first argument followed by your program? Wouldn't a user then be able to launch that program followed by the contents of a big file of say 5 gig. Wouldn't that overflow the dynamic array? Would the program gracefully exit or crash with a cryptic error? |
October 09, 2012 Re: bigger then size_t | ||||
---|---|---|---|---|
| ||||
Posted in reply to maarten van damme | On Tuesday, 9 October 2012 at 15:56:15 UTC, maarten van damme wrote:
> Wouldn't a user then be able to launch that program followed by the contents of a big file of say 5 gig.
The operating system won't allow that. There's a limit on argument sizes enforced before the program actually runs.
|
October 09, 2012 Re: bigger then size_t | ||||
---|---|---|---|---|
| ||||
Posted in reply to Adam D. Ruppe | Ok, that solves it. Thank you. |
October 09, 2012 Re: bigger then size_t | ||||
---|---|---|---|---|
| ||||
Another quick question. When I know an array is going to have an length smaller then 255, can I use bytes as index or do I have to use size_t to make it portable across 64 bit platforms? |
October 09, 2012 Re: bigger then size_t | ||||
---|---|---|---|---|
| ||||
Posted in reply to maarten van damme | On 09-Oct-12 20:36, maarten van damme wrote: > Another quick question. When I know an array is going to have an > length smaller then 255, can I use bytes as index or do I have to use > size_t to make it portable across 64 bit platforms? > The real question is why you need that? Byte is not faster (if not slower). And again you still need to cast to size_t and back (as .length is size_t). The only value could probably be to have indexes occupy less space (if you store them somewhere). Still this needs some extra checks (or at least asserts). -- Dmitry Olshansky |
October 09, 2012 Re: bigger then size_t | ||||
---|---|---|---|---|
| ||||
Posted in reply to Adam D. Ruppe | On 09-Oct-12 19:35, Adam D. Ruppe wrote: > On Tuesday, 9 October 2012 at 15:56:15 UTC, maarten van damme wrote: >> Wouldn't a user then be able to launch that program followed by the >> contents of a big file of say 5 gig. > > The operating system won't allow that. There's a limit on argument sizes > enforced before the program actually runs. I'll just add the follwoing: And how do you think shell does call program? Via syscall(s). And that syscall is just like (+- internal details) a normal C function call. And thus all arguments are always loaded into RAM first in *any* case. It's up to this program (shell, or whatever executes your program) to load that. And it will either truncate command line or fail itself. Also OS have some sane limits on command line length. IRC it's around 32768 in Windows. -- Dmitry Olshansky |
Copyright © 1999-2021 by the D Language Foundation