Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

"Inside STL: The vector" by Raymond Chen

50 views
Skip to first unread message

Lynn McGuire

unread,
Aug 3, 2023, 5:35:57 PM8/3/23
to
"Inside STL: The vector" by Raymond Chen
https://devblogs.microsoft.com/oldnewthing/20230802-00/?p=108524

"The C++ language comes with a standard library, and although
implementations are welcome to implement the library types in whatever
manner they choose, they are constraints imposed by the standard which
often force one of a small number of possible implementations."

"The std::vector is one of those types which is constrained to the point
that there’s really only one viable implementation."

Lynn

Pavel

unread,
Aug 5, 2023, 2:02:59 PM8/5/23
to
This does not sound correct. At least, one can change how the vector
grows, how it stores capacity and size and whether it is a monolithic
class or composed of reusable pieces... decisions, decisions, decisions.


>
> Lynn


-Pavel

wij

unread,
Aug 7, 2023, 4:41:07 PM8/7/23
to
The problem with std::vector is that the role is not clear.
Impl. aside, libwy https://sourceforge.net/projects/cscall/files/latest/download
clearly defines Array<T> as a wrapper of malloc(2) or the like.

This is lastly added example a_sysinfo.cpp (collect and dump system information)

#include <Wy.stdio.h>
#include <Wy.unistd.h>
#include <Wy.time.h>
#include <sys/utsname.h>

using namespace Wy;

String getfile(const char* fname)
{
Errno r;
String str;

cout << "---------------- Dump file: " << fname << " -----------------" WY_ENDL;
if((r=Wy::access(fname,F_OK))!=Ok) { // showcase, this check is not necessary
return "File (" + String(fname) + ") reading error: " + wrd(r) + WY_ENDL;
}

RegFile regf(fname,O_RDONLY); // may be virtual files (file size=0),
RdBuf strm(regf); // get_whole_regfile(..) won't work
for(;strm.is_eof()==false;) {
if((r=strm.append_read(str))!=Ok) {
WY_THROW(r);
}
if(str.size()>1000000) {
WY_THROW( Errno(EFBIG) ); // file size > 1-mega bytes
}
}
return str;
};

void dump_sysinfo() {
Errno r;
String str;

cout << "hostname: " << Wy::gethostname() << WY_ENDL;
{
struct utsname buf;
if(::uname(&buf)!=0) {
WY_THROW( Errno(errno) );
}
cout << WY_ENDL;
cout << "---------------- Dump struct utsname -----------------" WY_ENDL;
cout << "sysname : " << buf.sysname << WY_ENDL;
cout << "nodename: " << buf.nodename << WY_ENDL;
cout << "release : " << buf.release << WY_ENDL;
cout << "version : " << buf.version << WY_ENDL;
cout << "machine : " << buf.machine << WY_ENDL;
}

cout << WY_ENDL;
cout << "ttyname(cerr): " << ttyname(cerr) << WY_ENDL;
cout << "ttyname(cin): " << ttyname(cin) << WY_ENDL;
cout << "ttyname(cout): " << ttyname(cout) << WY_ENDL;
cout << "ctermid(): " << ctermid() << WY_ENDL;
cout << WY_ENDL;
cout << "timezone: " << local_tzname() << WY_ENDL;
cout << WY_ENDL;
cout << "current working directory: " << getcwd() << WY_ENDL;

cout << WY_ENDL;
cout << getfile("/etc/os-release");
cout << WY_ENDL;
cout << getfile("/proc/cpuinfo");
cout << WY_ENDL;
cout << getfile("/proc/version");
cout << WY_ENDL;
cout << getfile("/proc/meminfo");
cout << WY_ENDL;
};

int main(int argc, const char* argv[])
try {
dump_sysinfo();
return 0;
}
catch(const Errno& e) {
cerr << wrd(e) << WY_ENDL;
return e.c_errno();
}
catch(...) {
cerr << "main() caught(...)" WY_ENDL;
throw;
};

0 new messages