Why is SQLite written in C?

C is the best choice

Since May 29, 2000, SQLite has chosen the C language. To this day, C is the best language for implementing software libraries like SQLite.

Reasons why C is the best language to implement SQLite include:

  • performance.
  • compatibility.
  • Low dependency.
  • stability.

performance

A heavily used base library like SQLite needs to have good performance (SQLite is really fast, check out the articles Internal Versus External BLOBs and 35% Faster Than The Filesystem).

The C language is very suitable for writing programs with such performance requirements. The C language is sometimes referred to as "portable assembly language", allowing developers to get as close to the underlying hardware coding as possible while maintaining cross-platform portability.

Of course, there are other programming languages ​​that claim to be as fast or faster than C, but none are as versatile as C.

compatibility

At present, almost all systems can call libraries written in C language.

For example, an Android application written in Java can use SQLite through an adapter. This would certainly be more convenient for Android if SQLite was written in Java. But on iPhone applications are written in Objective-C or Swift, neither of which can call Java libraries. So if SQLite chooses to be written in Java, it won't work on the iPhone.

low dependency

Writing a library in C doesn't have too many dependencies at runtime. With minimal configuration, SQLite only needs the C standard library:

  • memcmp()
  • memcpy()
  • memmove()
  • memset()
  • strcmp()
  • strlen()
  • strncmp()

In more complex configurations, SQLite may also use malloc(), free() and some operating system interfaces to open, read, write and close files. But even then, the number of dependencies is very small.

stability

This stability refers to the stability of the language. The C language may be old and boring, but it is just right for developing more long-term stability-oriented modules like SQLite.

原文:Why Is SQLite Coded In C

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324433764&siteId=291194637