New answers tagged

1

I'm sorry to be so straightforward: This is madness! Your code seems to indicate a sincere lack of several language features. Pointer to const You define MEM to be of type uint8_t*, but it actually points to values of const uint8_t. To account for this difference you cast the const away in both constructors. If you'd ever (accidentally) write to the ...


10

Quick Review An API like this, dealing with thread-sensitive operations, requires time and effort to test and review rigorously. When I will find this time, I will do a thorough review. But here are some things I notice right off the bat. CommMemoryDisposedException should inherit from ObjectDisposedException. This way, consumers can handle your exception ...


3

private void _timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { lock (_syncObject) { if (_isDisposing) { return; } try { _timer.Stop(); Elapsed?.Invoke(sender, e); } finally { _timer.Start(); } } } As ...


4

Review property Interval and methods ExternalStart, ExternalStart should throw ObjectDisposedException if _isDisposing is true property Interval and methods ExternalStart, ExternalStart should also acquire a lock on _syncObject when implementing the dispose pattern make sure to include a destructor ~DisposableSafeTimer or seal your class _isDisposing should ...


2

First of all, you should always run clippy: error: this public function dereferences a raw pointer but is not marked `unsafe` --> src/lib.rs:20:29 | 20 | ffi::CStr::from_ptr(text) | ^^^^ | = note: #[deny(clippy::not_unsafe_ptr_arg_deref)] on by default = help: for further information visit https://rust-...


1

// buffer which should be faster than std::vector<uint8_t> when resizing a lot because it does not do byte initialization when resizing This comment line is really long. You should wrap the text so that there is no horizontal scrollbar anymore. class uint8_fast_buffer { public: uint8_fast_buffer(const size_t initial_size) Undeclared identifier ...


2

I prefer using the likely() macros over __builtin* directly.


1

Using this-> to refer to class members Ditch this. It's unnecessary unless you need to have to refer to inherited members or disambiguate any other variables or parameters.


1

getHeight and getWidth should be const. int getWidth() const { return width; } int getHeight() const { return height; } Your destructor does not properly delete the pixels pointer. Since you allocate it with new[] you need to use delete[]. delete [] pixels; You're storing your textures in column-major order. Depending on how you access them, this can ...


5

You must definitely call handle.Free() when finished using it so GC can do the cleaning. Note that GCHandle.Alloc(objects, GCHandleType.Pinned); only works for structs with pure primitive or to be more precise: blittable types. String fields etc. must be handled differently. A little optimization: You repeatedly calculate this var offset = Marshal....


2

Based on your question, a similar question I asked yesterday, and some of the answers, I did a version that tries to have the benefits of all of them. Disclaimer: Code is GCC specific (although probably works in similar compilers such as Clang). Usage: int *p; /* Want >int p[47];< */ if (mallocs(&p, 47)) goto err; ... free(p); ...


2

Apparently, collections are optimized for performance over memory management. So I'm afraid it is up to us, consumers of the .NET Framework, to implement memory management on collections that grow big and require lots of manipulations. I would use a scheduled task to periodically make a new instance of the queue, with the values of the previous instance, ...


4

Instead of flattening arguments into the string $Command, I'd suggest leaving these arguments in $@ by using shift: MaxMemory=$1; shift MaxTime=$1; shift # Command is now in $@ (Alternatively, read $1 and $2, then shift 2 for the same result.) We can produce output using portable printf instead of non-portable echo -e; it's probably a good idea to send ...


5

Command="$3" for (( i=4 ; i<="$#"; i++)); do Command="${Command} ${!i}" done # … ${Command} & Much cleaner to just reference the end of the $@ array directly. Since you're running the commands later, and would like to keep quoting intact, use an array: declare -a Command=( "${@:3}" ) "${Command[@]}" & # Break if the process has stopped ...


Top 50 recent answers are included