Skip to content

Commit bfff9e6

Browse files
committed
Remove the C4251 warning elements from sc_benchmark.h, adjust code.
1 parent b2287b3 commit bfff9e6

4 files changed

Lines changed: 36 additions & 35 deletions

File tree

src/base/sc_benchmark.cc

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#endif
1414

1515
#include <assert.h>
16+
#include <stdio.h>
1617
#include <iostream>
1718
#include <fstream>
1819
#include <iomanip>
@@ -83,8 +84,7 @@ benchVals getMemAndTime()
8384

8485
// --------------------- benchmark class ---------------------
8586

86-
benchmark::benchmark(std::string description, bool debugMessages, std::ostream &o_stream): ostr(o_stream),
87-
descr(description), debug(debugMessages), stopped(false)
87+
benchmark::benchmark(bool debugMessages): debug(debugMessages), stopped(false)
8888
{
8989
initialVals = getMemAndTime();
9090
}
@@ -94,10 +94,14 @@ benchmark::~benchmark()
9494
if(!stopped) {
9595
stop();
9696
if(debug) {
97-
ostr << "benchmark::~benchmark(): stop was not called before destructor!" << std::endl;
97+
std::cerr << "benchmark::~benchmark(): stop was not called before destructor!" << std::endl;
9898
}
9999
out();
100100
}
101+
if (benchVals_str) {
102+
free((void *)benchVals_str);
103+
benchVals_str = NULL;
104+
}
101105
}
102106

103107
void benchmark::stop()
@@ -129,32 +133,34 @@ benchVals benchmark::get()
129133
return delta;
130134
}
131135

132-
void benchmark::reset(std::string description)
133-
{
134-
descr = description;
135-
reset();
136-
}
137136
void benchmark::reset()
138137
{
139138
stopped = false;
140139
initialVals = getMemAndTime();
141140
}
142141

143-
std::string benchmark::str()
142+
const char *benchmark::str()
144143
{
145144
return str(get());
146145
}
147146

148147
void benchmark::out()
149148
{
150-
ostr << str() << std::endl;
149+
std::cout << str() << std::endl;
151150
}
152151

153-
std::string benchmark::str(const benchVals &bv)
152+
const char *benchmark::str(const benchVals &bv)
154153
{
155154
std::stringstream ss;
156-
ss << descr << " Physical memory: " << bv.physMemKB << "kb; Virtual memory: " << bv.virtMemKB;
155+
ss << " Physical memory: " << bv.physMemKB << "kb; Virtual memory: " << bv.virtMemKB;
157156
ss << "kb; User CPU time: " << bv.userMilliseconds << "ms; System CPU time: " << bv.sysMilliseconds << "ms";
158-
return ss.str();
157+
if (benchVals_str) {
158+
free((void *)benchVals_str);
159+
benchVals_str = NULL;
160+
}
161+
benchVals_str = (char *)calloc(ss.str().length() + 1, sizeof(char));
162+
snprintf(benchVals_str, ss.str().length(), "%s", ss.str().c_str());
163+
benchVals_str[ss.str().length()] = '\0';
164+
return benchVals_str;
159165
}
160166

src/base/sc_benchmark.h

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
#include "sc_export.h"
66

77
#ifdef __cplusplus
8-
#include <iostream>
98
#include <iosfwd>
10-
#include <string>
119

1210
#include "sc_memmgr.h"
1311
extern "C" {
@@ -43,34 +41,26 @@ class SC_BASE_EXPORT benchmark
4341
{
4442
protected:
4543
benchVals initialVals, laterVals;
46-
#ifdef _MSC_VER
47-
#pragma warning( push )
48-
#pragma warning( disable: 4251 )
49-
#endif
50-
std::ostream &ostr;
51-
std::string descr;
52-
#ifdef _MSC_VER
53-
#pragma warning( pop )
54-
#endif
5544
bool debug, stopped;
45+
char *benchVals_str = NULL;
46+
5647
public:
57-
benchmark(std::string description = "", bool debugMessages = true, std::ostream &o_stream = std::cout);
48+
benchmark(bool debugMessages = true);
5849

5950
/// if 'stopped' is false, uses str(true) to print to ostream
6051
~benchmark();
6152
void reset();
62-
void reset(std::string description);
6353
benchVals get();
6454
void stop();
6555

6656
/// converts data member 'laterVals' into a string and returns it
67-
std::string str();
57+
const char *str();
6858

6959
/// outputs result of str() on ostream 'ostr'
7060
void out();
7161

7262
/// converts 'bv' into a string, prefixed by data member 'descr'
73-
std::string str(const benchVals &bv);
63+
const char *str(const benchVals &bv);
7464
};
7565

7666

src/cllazyfile/lazy_test.cc

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
#include <iostream>
2+
#include <string>
13
#include "lazyInstMgr.h"
2-
#include <sc_benchmark.h>
34
#include "SdaiSchemaInit.h"
45
#include "sc_memmgr.h"
6+
#include "sc_benchmark.h"
57
#include <sc_cf.h>
68

79
#ifndef NO_REGISTRY
@@ -148,13 +150,15 @@ int main(int argc, char **argv)
148150
#endif //NO_REGISTRY
149151

150152
instanceID instWithRef;
151-
benchmark stats("================ p21 lazy load: scanning the file ================\n");
153+
benchmark stats;
154+
std::cout << "================ p21 lazy load: scanning the file ================\n";
152155
mgr->openFile(argv[1]);
153156
stats.stop();
154157
benchVals scanStats = stats.get();
155158
stats.out();
156159

157-
stats.reset("================ p21 lazy load: gathering statistics ================\n");
160+
std::cout << "================ p21 lazy load: gathering statistics ================\n";
161+
stats.reset();
158162

159163
int instances = mgr->totalInstanceCount();
160164
std::cout << "Total instances: " << instances << " (" << (float)(scanStats.userMilliseconds * 1000) / instances << "us per instance, ";
@@ -197,7 +201,8 @@ int main(int argc, char **argv)
197201
#endif //NO_REGISTRY
198202

199203
stats.out();
200-
stats.reset("================ p21 lazy load: freeing memory ================\n");
204+
std::cout << "================ p21 lazy load: freeing memory ================\n";
205+
stats.reset();
201206
delete mgr;
202207
//stats will print from its destructor
203208
}

src/test/p21read/p21read.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
*/
1414

1515
extern void SchemaInit(class Registry &);
16-
#include "sc_version_string.h"
1716
#include <STEPfile.h>
1817
#include <sdai.h>
1918
#include <STEPattribute.h>
@@ -94,7 +93,7 @@ void checkSchemaName(Registry &reg, STEPfile &sf, bool ignoreErr)
9493

9594
void printVersion(const char *exe)
9695
{
97-
std::cout << exe << " build info: " << sc_version << std::endl;
96+
std::cout << exe << " build info: " << SC_VERSION << std::endl;
9897
}
9998

10099
void printUse(const char *exe)
@@ -155,7 +154,8 @@ int main(int argc, char *argv[])
155154
STEPfile sfile(registry, instance_list, "", strict);
156155
char *flnm;
157156

158-
benchmark stats("p21 ReadExchangeFile()");
157+
// p21 ReadExchangeFile()
158+
benchmark stats();
159159

160160
cout << argv[0] << ": load file ..." << endl;
161161
if(argc >= (sc_optind + 1)) {

0 commit comments

Comments
 (0)