Jump to content

  • Log In with Google      Sign In   
  • Create Account

Pink Horror

Member Since 02 Jul 2013
Offline Last Active Jun 28 2016 09:50 PM

Posts I've Made

In Topic: Microsoft Checked C

24 June 2016 - 06:09 PM

Very little of any software "has to be" written in C anymore.

Entire huge games have been shipped with no C in them, for example. Of the things you listed, the C implementation is usually for compatibility with non-C languages, not to espouse C directly!

I have an entire language and compiler toolchain written with 0 dependencies on raw C. It has support for speaking the C ABI, but that has nothing to do with the C language being a mandatory component of anything.

The pieces of software that are in C are usually some of the most hardened and well-tested portions, for several reasons - not least of which being the fact that they usually exist to interface with non-C languages.

The effort of rewriting C code into Checked C is nontrivial. The reward is marginal at best for already-bulletproofed code. I just don't see a compelling reason for adoption.

It's a nifty project from a languages standpoint, but I don't see it being revolutionary.

And of course, if it "has to be" written in C, you cannot write it in Checked C.

In Topic: Microsoft Checked C

17 June 2016 - 07:54 PM


It also most definitely does not include anything even close to weak_ptr.

Are you sure? When reading it through, it looked like ptr<T> was designed to NULL out when the original data was invalid. That is the functionality from std::weak_ptr<T> that would be very nice.

No. This doesn't solve anywhere near enough real problems compared to just using modern C++.

C++ can't solve this issue because it itself is based upon potentially dangerous C libraries. As a library consumer, C++ (even Java and C#) seem better than C but remembering that underneath all their hoods, the same dangers can (and almost certainly do) still lurk, it removes all the fun ;). Plus these languages end up running more C than a C program due to their additional layers written in C so they are still not ideal.

Checked C aims to remove these issues at a much lower level than possible by just bolting on another random language.


The paper says it is about bounds-checking. a weak_ptr has nothing to do with bounds checking. The introduction is entirely about bounds-checking. It mentions problems such as using already-deleted memory are beyond the scope of Checked C.

C++ can at least partially solve the issue, because you can use templates to create the checked pointer classes. That's what the team who made this did as a prototype.

Just building with Checked C instead of C gets you nothing. You have to use the new types. Converting one of those potentially dangerous libraries to Checked C means putting in the correct changes to use bounds-checking everywhere they would belong, and making no mistakes or oversights while doing so. As long as you're rewriting chunks of the library, why not rewrite them in C++? What's the difference? How does the library go from potentially dangerous to knowing it's safe? How do you know you did the conversion correctly? How do you know the library isn't dangerous because of something that wasn't covered, like memory allocation?

If, for some reason, you have a code base that's in C, and you're willing to rewrite every part of it that uses pointers, and compiling it in C++ scares you and/or you're not willing to create the helper templates yourself, but compiling it in a new version of C from Microsoft is something you're willing to do, and you're having trouble with buffer overflows, and compile-time checks will help or run-time crashing is ok, than sure, Checked C might solve a problem for you.

In Topic: Need some advice or direction on a Mod friendly data structure.

10 June 2016 - 08:29 PM

Large databases with around 40TB of data presently.


You mention a millisecond.


Kept in local memory lookup, that is on the order of tens of nanoseconds.


Use the nanosecond-speed one when possible.

So, you're saying that Tangletail's game's DB performance will be similar to a 40TB database, and that one frame of a typical  video game happens in tens of nanoseconds?

In Topic: Need some advice or direction on a Mod friendly data structure.

09 June 2016 - 07:54 PM

Big relational databases work well for persistence, but realize that queries are time consuming. Even fast queries to an RDBMS take longer than most video game frames. If you're storing a lot of data and reading it as part of loading a character or map or level it can work, but they are a poor choice for this type of data.

I don't know what database you're using, but on the servers I typically work with, the complete round-trip time of sending a simple, plain-text SQL query over the network to another server, processing it, and getting the result back often takes less than one millisecond. I'm sure a game could do it even faster with a local, in-memory database. And actually, I know that's true, because I've also worked on a game that did that.

In Topic: use ID or Pointers

07 June 2016 - 08:37 PM


Add "no type-safety" to the "cons" list for integer handles/IDs, please.

You can add integer ID's (and void* ID's!) to the C++ type system like this, in order to maintain type safety:
struct PrimitiveBase {};
template<class T, class Name> struct PrimitiveType : PrimitiveBase
	typedef T Type;
	PrimitiveType() : value() {}
	explicit PrimitiveType(T v) : value(v) {}
	operator const T&() const { return value; }
	operator       T&()       { return value; }
	T value;

#define MAKE_PRIMITIVE_U64(name)					struct tag_##name; typedef PrimitiveType<u64,tag_##name> name;
#define MAKE_PRIMITIVE_U32(name)					struct tag_##name; typedef PrimitiveType<u32,tag_##name> name;
#define MAKE_PRIMITIVE_U16(name)					struct tag_##name; typedef PrimitiveType<u16,tag_##name> name;
#define MAKE_PRIMITIVE_S16(name)					struct tag_##name; typedef PrimitiveType<s16,tag_##name> name;
#define MAKE_PRIMITIVE_U8(name)						struct tag_##name; typedef PrimitiveType<u8,tag_##name> name;
#define MAKE_PRIMITIVE_S8(name)						struct tag_##name; typedef PrimitiveType<s8,tag_##name> name;
#define MAKE_PRIMITIVE_PTR(name)					struct tag_##name; typedef tag_##name* name;
class Foo
  MyObjectId Create();
  void Release( MyObjectId );

What does PrimitiveBase do for you in this case?