Reputation: 549
First a bit of background:
I am using Visual Studio 2017 - Professional Addition
Developing a native C++ android application
I used the standard template. So I have a pure c++ (11) library where all my code is. And a precompiled header defined in the main project that links to my library.
What I am doing
I am working on some code that requires a large amount of embedded data.
I googled around for good ways to do this, but most seem like way to much hassle and almost always there were comments saying just to put the data directly into header files as that's the most portable way.
So I now have a number of header files that basically contain static arrays of data. NOTE they are not 'const' as if you do that then Visual Studio 2017 will try and display the data if you happen to move over the variable definition. So just static.
All the header files are then aggregated into one header file and this is then finally referenced in a standard cpp file. effectively making the data private to that class.
This all works fine. BUT compile times are getting to be very slow. And if I watch the output window I can see that it spends 80% of its time on the cpp file (even when there have been no changes to the data or the code)
Now this cant be the best a compiler can do. I would expect the compiler to skip this as there have been no changes that directly effect the cpp file.
I have also attempted to move things into the precompiled header. But that simply makes the pch.h file take ages to build each time.
So what am I doing wrong?
Update
I have double checked the files have not been changed. If I press F6 (build) then press again, it will still rebuild the large files.
I have also tried reworking the static data so that it is defined in a cpp file. And this still makes no difference.
For clarity this is an example:
.cpp file:
#include "Some.h"
unsigned char _someData[] =
{
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
};
unsigned char* Some::GetSomeData(void)
{
return _someData;
}
.h file:
#pragma once
class Some
{
public:
static unsigned char* GetSomeData(void);
};
Upvotes: 3
Views: 1202
Reputation: 8333
In manner to save compilation time try the following:
extern
of the data variables in the headers.#include <file>
and #include "file"
. if you choose the wrong include method, (like use <> to include your file, or "" for system include) you spend more time in search for the file.If you wan't to know why a project or file is re-built or re-compiled even though there was no changes, you can do it as follows:
Good luck
Upvotes: 2
Reputation: 2122
You can consider using data files (outside your code), that you read when you program starts. This will create some overhead (file reading time) but you will solve your compilation time problems.
Upvotes: 1