Ariana
ok that is painful
Hackers
Wow!
Hackers
BinaryByter
USE REALLOC
BinaryByter
(unless you haven't implemented realloc yet)
Mihail
op said he's using c
BinaryByter
so?
BinaryByter
what does OP mean?
Mihail
BinaryByter
oh
Mihail
and he suggested using std::vector
BinaryByter
oh
BinaryByter
in general
BinaryByter
just don't use C
Mihail
true
Mihail
but if he's already got a C codebase a conversion won't be easy and for such a small thing
BinaryByter
why would anybody have a C codebase?
Anonymous
Anonymous
systems without heaps
Anonymous
Ludovic 'Archivist'
C is great
Maybe for very small projects in code size
Victor
very small, less then 1 KB→_→
Victor
I think assembly can be used =_=
Victor
the compiled binary is less than 1KB 😏
Victor
wait, that is not an actual compilation, but assembling 😏
Ludovic 'Archivist'
Ludovic 'Archivist'
Ludovic 'Archivist'
And 99.95% of the time, C++ is not slower than C
Anonymous
Ludovic 'Archivist'
The 0.05% that subside are generally what is made my idiots that do not know the language
Anonymous
C seems more minimalistic and it seems to work very well for what I do
Ludovic 'Archivist'
Anonymous
Anonymous
Anonymous
Ludovic 'Archivist'
Depends on the OS
Sometimes, none, the rest of the time, that is 99%, Linux with no hardening and an insecure telnet server but that is another thing
Ludovic 'Archivist'
Ludovic 'Archivist'
Nowadays, not so much
Ludovic 'Archivist'
Medical equipment may be the most terrifying thing I ever audited
Anonymous
Etaoin
in Haskell we can define
x /= y = not (x == y)
x == y = not (x /= y)
in a typeclass
Etaoin
but how can I do this in C++?
Etaoin
I mean
class A{
public:
int f() {
return 1;
}
int g() {
return f();
}
};
class B:public A{
public:
int f() {
return 2;
}
};
int main() {
B x;
cout<<x.f()<<x.g();
return 0;
}
gives 21
Victor
Etaoin
yes
Victor
That is very normal.
Victor
What do you expect?
Etaoin
I want to expose a interface to my user, that they can either implement function f or function g
and with for some reason, g can be done by calling f and vice versa
Etaoin
for example f=(==) and g=(/=) in Haskell
Victor
Etaoin
class A actually act as a interface and B is what the user (not I) writes that implement this interface
Etaoin
I expect both f and g in this interface, but either of them can be implemented with the other
Victor
Etaoin
and what's worse, it's in a performance bottleneck, so virtual function is not acceptable
Victor
Or do you mean user can either implement B::g() and use A::f() or implement B::f() and use A::g()?
Victor
Etaoin
and what's worse it's in a performance bottleneck so virtual function is not acceptable
Etaoin
Etaoin
it's kinda like this
Etaoin
Etaoin
this, works, of course
Ludovic 'Archivist'
Etaoin
I know, but I tried several times and did not find a good solution
Ludovic 'Archivist'
Ludovic 'Archivist'
You could make it a non interface class that stores function buffers (aka a size and a pointer) and relocates those in memory directly over pre-made placeholder, it will however not work correctly in multithreading
Etaoin
I think it could be done with templates
Ludovic 'Archivist'
But then if you can they will likely be optimized in the case of virtual functions in most cases
Ludovic 'Archivist'
Also, unless your CPU dates from before 2009, you likely have a very suitable vtable prediction algo that reduce the eventual overhead of it if it is not optimized away down to a single cycle
Ludovic 'Archivist'
Which, compared to a loop, is pretty much nothing unless you loop on a very tiny datastructures
Ludovic 'Archivist'
Also, virtual inheritance works with references, get rid of that IStatistics*