digitalmars.D.learn - bigger then size_t
- maarten van damme (2/2) Oct 09 2012 What happens when args[1].length is bigger then size_t?
- Dmitry Olshansky (7/9) Oct 09 2012 Then size_t.max? It can't as it has type size_t.
- maarten van damme (5/5) Oct 09 2012 But doesn't args[1] get filled by the first argument followed by your
- Adam D. Ruppe (4/6) Oct 09 2012 The operating system won't allow that. There's a limit on
- maarten van damme (1/1) Oct 09 2012 Ok, that solves it. Thank you.
- maarten van damme (3/3) Oct 09 2012 Another quick question. When I know an array is going to have an
- Dmitry Olshansky (9/12) Oct 09 2012 The real question is why you need that? Byte is not faster (if not
- Dmitry Olshansky (11/16) Oct 09 2012 I'll just add the follwoing:
What happens when args[1].length is bigger then size_t? Can I detect this?
Oct 09 2012
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
Oct 09 2012
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?
Oct 09 2012
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.
Oct 09 2012
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?
Oct 09 2012
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
Oct 09 2012
On 09-Oct-12 19:35, Adam D. Ruppe wrote:On Tuesday, 9 October 2012 at 15:56:15 UTC, maarten van damme wrote: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 OlshanskyWouldn'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.
Oct 09 2012