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

Why ‘int’ instead of ‘size_t’ #7

Open
cesss opened this issue May 29, 2019 · 5 comments
Open

Why ‘int’ instead of ‘size_t’ #7

cesss opened this issue May 29, 2019 · 5 comments

Comments

@cesss
Copy link

cesss commented May 29, 2019

I know neatvi aims to be small, but why did you choose ‘int’ variables for buffer sizes and cursor positions, instead of ‘size_t’ ? Even if neatvi is small, using ‘size_t’ variables would make it possible to open huge files.

BTW, can cursor positions (or sizes) become negative? If they can never be negative, maybe it’s straightforward to just replace the proper ‘int’ variables by ‘size_t’ ones.

@aligrudi
Copy link
Owner

aligrudi commented May 31, 2019 via email

@cesss
Copy link
Author

cesss commented May 31, 2019

I believe the real point here is not 'size_t' vs 'int', but 'unsigned' vs 'signed'. For example, if all your variables were unsigned, then using 'size_t' instead of 'int' is just a matter of a typedef, because 'size_t' is unsigned. Of course, there's also a signed version of 'size_t', called 'ptrdiff_t' IIRC.

Most of the times you edit small to moderate files. But there's always one day when you face a file over 4GB. And then, that day you realise you don't have a proper open-source editor for it, and the only option is to purchase a commercial editor (it happened to me).

So, I find it unfortunate that neatvi is not ready for using 64bit address spaces.

Do you know of any other vi implementation ready for >4GB files?

@aligrudi
Copy link
Owner

aligrudi commented May 31, 2019 via email

@cesss
Copy link
Author

cesss commented Jun 1, 2019

I think that rather than redefining 'int' as 'long', it does make more sense to use standard sized integers, because the meaning for 'short', 'long', 'long long', etc... can be totally different from platform to platform. If the platform you are compiling to doesn't have the (now standard) header for sized integers, you can always provide a fallback path in the Makefile for manually defining them for your platform.

For example, I think it would be really useful to be able to build neatvi being able to choose the buffer size in bits at build time (eg: choose to build neatvi for 16bit, 32bit, or 64bit sized buffers).

Regarding not bringing the whole file into memory when it's large, I agree if it's for avoiding an unnecessary write of several GBs into the disk just when you just modified an small fraction of the file. For example, SQLite doesn't overwrite the whole database when you save it, but just the bytes you changed. But if the reason is for avoiding pushing the RAM usage in your machine, I don't see it as an important reason (yes, it can be handy to be able to limit the RAM usage, but I see it more as a "bonus feature" than a required thing, while avoiding unnecessary disk writes is a requirement IMHO).

Note that you should be able to avoid unnecessary disk writes while having the whole file in RAM at the same time: if the editor has some means of tagging as "dirty" the parts of the file you modified, it should be able to rewrite just those parts and not the whole file.

@aligrudi
Copy link
Owner

aligrudi commented Jun 1, 2019 via email

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

2 participants