Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Internal file limit of 255 open files #1

Open
japanoise opened this issue Sep 9, 2023 · 1 comment
Open

Internal file limit of 255 open files #1

japanoise opened this issue Sep 9, 2023 · 1 comment

Comments

@japanoise
Copy link
Owner

255 is an awful lot, but if you're using sam as your primary editor and are lazy about cleaning up files it is possible to hit it.

  1. Have a directory with >255 files.

    1. Execute sam *.

    2. samterm:panic: menuins: Resource temporarily unavailable

Edit: It's a samterm's limitation in samterm.h:

`#define MAXFILES    256

Plan9port's sam doesn't have this limit, and since sam was intended to easily modify many files, I think this sam should remove it, too.

Sam's lack of internal limits and sizes is a virtue. Because it avoids all fixed-size tables and data structures, sam is able to make global changes to files that some of our other tools cannot even read.
—Rob Pike, The Text Editor sam

deadpixi#110

A quick ag for this constant reveals it's used to initialize static sized arrays in a few places:

~/src/sam master
❯ ag MAXFILES
samterm/menu.c
8:uint8_t   *name[MAXFILES];    /* first byte is ' ' or '\'': modified state */
9:Text    *text[MAXFILES];    /* pointer to Text associated with file */
10:uint16_t  tag[MAXFILES];      /* text[i].tag, even if text[i] not defined */
233:    if(nname == MAXFILES)

samterm/samterm.h
5:#define MAXFILES    256

The stupid solution would be to just increase this to some other limit (512 or 1024 to stick with nice round numbers), but that runs into two problems imho:

  1. How much memory does that use? It may be non-negligible. It's all well and good for me with my if-you-have-to-ask-you-can't-afford-it workstation with HOW MUCH!?!?!?!gb of RAM to go around allocating fucktonnes of memory, but until fairly recently I was editing on an X200 with only a few gigs; and being as we support 32-bit systems, maybe we shouldn't go crazy with memory usage.
  2. It's just kicking the can down the road. Someone will eventually hit that limit and re-open the issue.

I suspect a "stretchy" buffer would be the correct choice here (that is, a crude implementation of an arraylist, where we realloc the memory when we're in danger of running out). That would require a significant refactor.

PRs are open!

@japanoise
Copy link
Owner Author

The original issue does mention p9p's version doesn't have this limit; maybe some code could be snarfed from there?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant