|
|
Subscribe / Log in / New account

The "too small to fail" memory-allocation rule

The "too small to fail" memory-allocation rule

Posted Jan 19, 2015 18:33 UTC (Mon) by dgm (subscriber, #49227)
In reply to: The "too small to fail" memory-allocation rule by pal
Parent article: The "too small to fail" memory-allocation rule

I have never seen this rule (or at least not in that form). What I have seen is a guideline that hints that the code protected by a lock should be as small and straightforward as possible.

Your rule actually makes a lot of sense. Locks exists to ensure concurrent access to a shared resource in a coherent way. If you're calling "foreign" code, then your code is not just accessing the shared resource, and thus it is protecting too much. Probably the "right" thing to do is to move all resource allocations (including memory) outside the lock scope, and only acquire the lock once all the needed resources are ready.


to post comments


Copyright © 2025, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds