Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Joonas Koivunen
    @koivunej
    Well.. I guess Option<usize> and Result<usize, WhyPerformanceInfoReturnsNotTrue> or some more descriptive error type for this occasion might be more idiomatic. Just trying to give small enhancement ideas.
    Jan Hlavatý
    @hlavaatch
    winapi crate defines the struct with the STRUCT! macro that implements default as zeroed()
    but it needs impl-default feature enabled
    hmm, why not
    Jan Hlavatý
    @hlavaatch
    This looks nicer and nicer
    // on Windows, requires winapi crate with "psapi" and "impl-default" features enabled
    #[cfg(windows)]
    fn total_system_memory() -> Option<usize> {
        use winapi::shared::minwindef::{DWORD,TRUE};
        use winapi::um::psapi::{PERFORMANCE_INFORMATION,GetPerformanceInfo};
        use std::mem::size_of;
    
        let mut info = PERFORMANCE_INFORMATION::default();
    
        if unsafe { GetPerformanceInfo(&mut info, size_of::<PERFORMANCE_INFORMATION>() as DWORD)} == TRUE
        {
            Some(info.PhysicalTotal * info.PageSize)
        } else {
            None
        }
    }
    Joonas Koivunen
    @koivunej
    yeah it does :) what are you building though if total system memory impacts it?
    Jan Hlavatý
    @hlavaatch
    just need to size some memory buffers to take advantage of memory available
    it will be settable but need some guess for defaults
    Matthew Pocock
    @drdozer
    I think I'm still trying to understand rust futures
    I have an app that does a mix of web service calls (tokio_rt) and cpu-bound computation (using rayon, currently) and I'm not really sure how to partition the work
    so as I understand it, you build up a composite future as a data structure, and it only does something when you pass it into some run-time run method?
    e.g. tokio_system.block_on
    so then I'm not sure how I orchestrate passing results asynchronously or non-blockingly between two different runners (io and cpu bound)
    Jan Hlavatý
    @hlavaatch
    You can use task::spawn_blocking to launch CPU intensive tasks. Currently there is not much support for limiting number of threads or thread pools though, some necessary things like Semaphore have even been removed from public API (hopefully temporarily)
    pass data using channels
    tokio::sync::mpsc maybe
    i received some suggestiions like launching second runtime but dont like it much
    Matthew Pocock
    @drdozer
    thanks - I'll have a think
    at least doing this in rust I've not had any data corruption issues between the various async operations :)
    Edoardo Luppi
    @lppedd

    @hlavaatch

    things like Semaphore have even been removed

    Ouch, why?

    Jan Hlavatý
    @hlavaatch
    I have no idea, it is totally misguided
    Matthew Pocock
    @drdozer
    I ended up using a semaphore from futures-intrusive
    as it had a semaphore permit acquisition model that was a future over the permit
    but that semaphore is purely the protected counter -- it doesn't hand out N copies of a resource
    Jan Hlavatý
    @hlavaatch
    there needs to be tracking of who is waiting for permit to wake someone up when permit becomes available
    it may not be as easy as it looks
    Matthew Pocock
    @drdozer
    right, and there's a degree of choices over the "who" that may be more or less performant, and more or less prone to deadlocking on futures all waiting for each-other
    Denis Lisov
    @tanriol
    @hlavaatch I'm really unsure that MaybeUninit::uninit().assume_init() does not cause immediate UB (not sure what's the unsafe WG stance on this now). Is this structure big enough for this to be actually meaningful?
    Jan Hlavatý
    @hlavaatch
    This should be the proper way to do uninitialized data??
    Denis Lisov
    @tanriol
    The proper way is to allocate it with MaybeUninit::uninit(), fill using a raw pointer (no references yet) and only then call assume_init().
    This makes little to no difference if all the values are allowed in it (but I'm not sure about the current official stance). If there were a bool in this struct, this would be definitely UB.
    Jan Hlavatý
    @hlavaatch
    this structure has just bunch of DWORD and SIZE_Ts in it, its certainly safe
    anyway I later moved to using default() which does zeroed() inside
    Denis Lisov
    @tanriol
    The specific question of whether uninitialized bytes are allowed in integers is discussed in rust-lang/unsafe-code-guidelines#71, if you're interested in the details :-)
    Jan Hlavatý
    @hlavaatch
    I can see uninitialized bits could be bad for floats, but in this case its just ints and nobody even looks at them before they are overwritten by the function, it's the poster child of uninitialized buffers, I'm pretty sure its ok ;)
    Mikail Bagishov
    @MikailBag
    If lang team will decide to deny uninitialized literals, than your code will have instant UB when you call assume_init no matter do you use this values or not.
    inzanez
    @inzanez
    I'm seeing many crates where functions on types are of the kind pub fn something(self,...) -> Self {...}. As far as I understand, this will call "Drop" (if implemented) at the end of the function,...and return what? A copy? Isn't that very expensive?
    Denis Lisov
    @tanriol
    This will not call drop if the function returns self and will return that value (possibly moving it, but that can be optimized away in some cases).
    The cost, obviously, depends on how complex the Self type is and how complex the methods are.
    inzanez
    @inzanez
    @tanriol Hm. So why is "Drop" being called if I return Result<(type of self),Error>? Because it's not Self that I return I assume,...
    Denis Lisov
    @tanriol
    Could you please show an example of what you're doing?
    inzanez
    @inzanez
    @tanriol of course: https://pastebin.com/37SMBtF0
    @tanriol executing the sample returns: "dropped, merged".
    @tanriol I see...because I do not assign.
    Denis Lisov
    @tanriol
    Yes, it's dropped after the function returns it.
    inzanez
    @inzanez
    many thanks! :-)
    Felipe Rocha
    @felipellrocha
    How do I run two streams concurrently?
    Denis Lisov
    @tanriol
    Which streams do you mean?
    Joonas Koivunen
    @koivunej
    @felipellrocha https://docs.rs/futures/0.3.1/futures/macro.select.html might be what you are looking for
    Matt Hicks
    @darkfrog26
    I'm currently learning Rust and I'm confused why :: for so many delimiters and . for others? Why not just use dot separation for everything like most modern languages? Is there a logical reason for this or is just legacy ties back to C?