HNHacker News
TopNewBestAskShowJobs

habibur

2,635 karma · joined August 26, 2008

habib@habibur.com
submissionscomments
habibur··on A simple, arena-backed, generic dynamic array for C

    #include <stdio.h>
    #include <stdlib.h>

    int main(){
    int same=0;
    int moved=0;
    char* temp=malloc(16);
    for(int i=0; i<10000; i++){
        char* temp2=realloc(temp,(i+2)*16);
        if(temp!=temp2){
            moved++;
            temp=temp2;
        }
        else same++;
    }
    printf("ptr moved %d, reused %d times\n",moved,same);
    }
Tried the above. Ptr moved 7 times and is reused 9993 times.

But, what you want to test is what you identify as your need.

No point in explaining more.

habibur··on A simple, arena-backed, generic dynamic array for C
> Or am I wrong? How large is your initial alloc?

Zero. Most of the time. When I don't know the exact requirement before hand.

> Reason is that I would expect the allocator to, normally, allocate blocks tight together and most reallocations to grow the size by more than the granularity of the memory allocator

Now look at it like this. Even if I wrote my own allocator with malloc(), free() and realloc(), I would have written it such a way that the first time I found a pointer getting realloc()-ed I would have added an extra 60% at its end assuming this pointer has a trend to grow. And for subsequent small increment calls use space at the end.

I don't see why C library's allocator writers wouldn't have thought the same. Even if on some platform it's not done for some reason, that can be replaced with your own implementation.

Add with it the fact that OS is also optimizing your memory usage, your allocs are virtual pages mapped to actual physical ram. And who knows how deep these caches go at processor level. You are basically caching over caching and so on.

This is similar to "reading a file in memory" because "accessing from disk is so slow". That's so much 90s thought. Your file will be cached in memory by the OS whenever you access it the first time and you have sufficient free RAM available for cache.

But one doesn't need to assume the above to be true. Simply measure and check for yourself. If your findings don't match your understandings, there are alternate explanations.

habibur··on A simple, arena-backed, generic dynamic array for C
And if you are not using arena -- realloc() is your best bet. And no, it won't move your memory around into larger areas every time you call it. Most of the time it will simply bump up the allocation end point. This happens more frequently than you think.

In my code I don't use allocated_length and used_length seperately in dynamic vectors. Simply realloc() every time one element is added. No measurable difference in speed, and code is much more clean.

habibur··on OpenSSH 9.5 released with keystroke timing obfuscation
There was a recent research paper shared here where it was claimed using keystroke timing and some AI, researchers could predict the password with significant accuracy.
habibur··on Running Stable Diffusion XL 1.0 in 298MB of RAM
Before you waste your time, this is a commercial product and you need to pay $30 to buy their model to run it.
habibur··on Meta in Myanmar
As bad as it is in Myanmar -- replace s/Meta/The Internet/g and then check if that makes any difference.

Control your population, not the tools they use. Stop the use of one, they will find an alternative that serves the same purpose.

habibur··on Arena allocator tips and tricks
Adding that when many linux distributions face OOM, a killer daemon steps in and might kill your service even if you were handling the situation properly.
habibur··on Platform that enables Windows driver development in Rust
> My take from the first book was that he has an extremly black and white view of the world.

Things change over age. He might be no longer such.

habibur··on Show HN: Tome, aka Tom's Editor – a new command-line text editor
Don't. Less dependency is better.
habibur··on Show HN: Tome, aka Tom's Editor – a new command-line text editor
That was the first thing I checked and surprisingly it's JS/node.

That kills it for me. Terminal apps in Python or JS works but are significantly slower, and you can feel it.

Talking in general. Not this one. I haven't tried this one.

habibur··on Show HN: Oyie – A micro social app to stay in sync with your friends
This market is currently dominated by IM group chats.

In fact, most of the old social media has now moved over to chat groups.

habibur··on Ask HN: Why did Visual Basic die?
New version of VB was VB.net.

People still used VB.net primarily as they were familiar with VB.

But the new projects gradually took over C#.net, as it sounded more cool.

VB.net died after a while.

habibur··on Ask HN: Why did Python win?
I see the flip happening when MIT switched from Lisp to Python for its introductory courses. That happened in the 00s. They had to choose between Java and some other langues and then choose Python. Gradually everyone else followed. New grads came out learning Python. They started developing with it and took over other langues.
habibur··on What is gained and lost with 63-bit integers? (2014)
use

    struct {
      enum type;
      union { int; double; long; void\*};
    }
and you don't need to box anything. no extra allocation for primary data types. no de-referencing of pointers unless the data is larger than the union size. you can pass this struct from function to function by value, as like it's an int64 or double.
habibur··on Inactive Google Account Policy
Back then, maybe two decades back, Google was seen as evil as it declined to acknowledge that it will delete user data after the user has closed its account.

Time changes.

habibur··on Pixar, Adobe, Apple, Autodesk, and Nvidia form alliance for OpenUSD
Anyone remembers VRML?
habibur··on Why is c the symbol for the speed of light? (1997)
I scroll to 70% and by then the secret is given out.
habibur··on How I run my servers (2022)
Also those hidden costs. You don't know about those until you are charged for it, and was written in their terms which you never bothered to read.
habibur··on HTTP vs. WebSockets: Which one is the fastest for Postgres queries at the edge?
First check if that can be done with a port forwarder or socks proxy.
habibur··on The Development of the C Language (1993)
Adding that anything I wrote in C++/MFC at that time is now obsolete.

Everything I wrote in C/Win32 is as much fresh as it had been 30 years back.

habibur··on Tell HN: People forget that you can stick any data at the end of a bash script
> What could possibly go wrong with emailing executable scripts?

Server side malware filters will strip the attachment.

habibur··on Red Hat Is Not Linux (2000)
More purity fight even before that. Remember, when pre-compiled kernels started to get popular, it was seen as bad thing, as everyone was supposed to compile their own kernel which took into consideration of their hardware configuration for optimization.
habibur··on At last, the Raspberry Pi shortage is finally coming to an end
I need to give it two more years to see how stable the supply really is, before planing to extend on it.

Right now it's basically supporting the old systems to keep those at least running.

habibur··on Google Analytics 4 was frustrating, so we built our own analytics service
1998 analytics used Apache log files as the only source.

Wondering if Apache log files are GDPR complient or not.

habibur··on Ask HN: How do I make a website in 2023?
If you are doing it alone then you don't need any of these. Go for simple HTML, JS, CSS and PHP server side.

The popular solutions you find online are for Enterprise. Where different teams maintain the same site and no one "owns" any part of the code.

habibur··on Language Learning with Netflix
Tried it. Didn't really work for me much.

Taking a slower approach using Youtube worked better.

habibur··on How are you using ChatGPT internally at your company?
OpenAI blocks all VPNs. Some get through regardless, those seem to be the exception.
habibur··on Italy lifts ban on ChatGPT after data privacy improvements
I would have loved to see it go on at least for a year and then see what happens.
habibur··on Physicists discover that gravity can create light
They attribute it to the fact that space around the object is bent. Which is causing the other object to drop, accelerate or bent. Check General Relativity's explanation of Gravity.

That might not answer all of your or my question. But maybe we didn't give enough time to ponder on that line.

habibur··on Physicists discover that gravity can create light
Or gravity is just bending of space around a mass. And not a force.
← PreviousPage 4 of 23Next →