How best to deal with gigantic source code files i

2020-07-19 04:15发布

I'm working on a project which makes substantial use of code generation. Some of the files it generates contain >0.25 million lines of code. VS (2K5) doesn't cope too badly, but R# (4.01) throws an out of memory exception every two minutes or so.

Splitting them out into partial classes/separate files isn't an option in the immediate term, though it may be later.

Are there any clever IDE tricks to dealing with this?

EDIT: so people are immediately saying (very sensibly) 'don't have a file that big' and suggesting ways to break it out into smaller files.

That's fine, but I'm on a time-boxed task taking a look around and deciding what to optimise. My problem is very specifically 'how to view an insanely big file in an IDE without pain', not 'how to refactor the project'. For purposes of the question please imagine the file is read-only. :)

8条回答
别忘想泡老子
2楼-- · 2020-07-19 04:54

Can't you break up the files and use the preprocessor to bring them back together when you compile?

查看更多
放我归山
3楼-- · 2020-07-19 04:55

Don't use visual studio. There is too much going on in VS.

Since the file is read only, you wont be using any IDE features (Intellisense, Refactoring tools, formatting).

You will probably get better performance using a simpler application, such as notepad++ for simply viewing the file. Notepad++ will do standard language highlighting if you like color.

查看更多
我只想做你的唯一
4楼-- · 2020-07-19 04:59

WOW!

250 000 lines of code?

you should think not in a machine point of view, but in a human been point of view. Let's say that you want to pass that code to someone else, can you see the time to see what the code does?

Design Patterns were made to deal with this ind stuff, try to start small, refactoring it, then go deeper and start applying more D.P.

you will have less and less lines of code, and Yes, one of the best tricks is to separate into several files according to it's propose.

查看更多
Deceive 欺骗
5楼-- · 2020-07-19 05:00

I would at least change huge files extention to something like .cpp_gen or .cpp_huge to remove syntax highlighting, outlining etc. and then reassign build tool back to C/C++ compiler tool for them.

查看更多
Melony?
6楼-- · 2020-07-19 05:02

Seems like this R# tool (is that Resharper?) is the problem. Can you disable it? Otherwise, changing the file type for the generated code might make sense - presumably, you aren't going to be doing major editing on those files, so losing syntax coloring and other features specific to source files wouldn't be an issue.

查看更多
Animai°情兽
7楼-- · 2020-07-19 05:08

Is the problem when you open the file for editing in Visual Studio? I've noticed that VS editor can be quite slow and inefficient on large files. Also, you could try turning off certain options, e.g. word-wrapping kills my machine for some reason.

Otherwise you could use something else like Textpad with syntax highlighting installed to edit the problematic large source file... not as nice, for sure.

查看更多
登录 后发表回答