kvark / copyless Goto Github PK
View Code? Open in Web Editor NEW[deprecated] Avoid memcpy calls when working with standard containers
License: Apache License 2.0
[deprecated] Avoid memcpy calls when working with standard containers
License: Apache License 2.0
I just ran across this and wanted to understand how this crate avoids memcpy. One thing I stumbled upon is this:
Line 10 in a174875
Why is this using mem::replace
, which seems like it'd do an unnecessary write, as opposed to let ptr = &mut *(self.0);
?
So I came across this while tinkering around on this.
The essence is that when trying to create a box of [[0i32;SomeBigNumber];SomeBigNumber]
the stack overflows, but when creating a box of [i32;SomeBigNumber*SomeBigNumber]
it works.
I would understand if this is something this crate cannot change (as its a missed opportunity from the compiler to optimize this) but wanted to ask if there is a known specific reason for this to not work?
I'm using the latest nightly and of course use cargo run --release
while testing this.
could be done as an optional feature
Current Travis integration is no longer sending the signals to GH properly, unfortunately.
It feels like there could be a box!
macro that would do Box::alloc().init(...)
.
I have a serious issue I cannot explain. My guess is that copyless creates some sort of memory issue when called with static functions.
assume the following traits:
pub struct Runnable {
runnable_box: Box<RunnableBox + Send>
}
impl Runnable {
pub fn run(self) {
self.runnable_box.run();
}
}
trait RunnableBox {
fn run(self: Box<Self>);
}
impl<F: FnOnce()> RunnableBox for F {
fn run(self: Box<F>) {
(*self)()
}
}
And these two constructors, one using Box::new, the other using Box::alloc().init
impl Runnable {
pub fn new_box<F>(func: F) -> Runnable
where
F: FnOnce() + Send + 'static {
Runnable { runnable_box: Box::new(func) }
}
#[allow(dead_code)]
pub fn new_copyless<F>(func: F) -> Runnable
where
F: FnOnce() + Send + 'static {
Runnable { runnable_box: Box::alloc().init(func) }
}
}
Creating a static Runnable seems to create some sort of memory overwrite I cannot exactly pin down:
Runnable::new_box(move || { println!("scheduled task 1"); }); // Works
Runnable::new_copyless(move || { println!("scheduled task 1"); }) // Error
let now = Instant::now();
Runnable::new_copyless(move || { println!("scheduled task 1 {:?}", now); }) // Works
I have attached a testcase that fails on macos and on linux using Rust 1.33 stable and rustc 1.35.0-nightly (0576ac109 2019-03-24).
It might be useful to be able to take an existing Box
and turn it back into a BoxAllocation
.
For example, you might want to use the same allocation twice like in this contrived example:
fn make_big_thing(box_alloc: BoxAllocation<Thing>) -> Box<Thing> {
box_alloc.init(...)
}
fn main() {
let box_alloc = BoxAllocation::init();
let thing = make_big_thing(box_alloc);
do_something_with_thing(&thing);
let box_alloc = BoxAllocation::from_box(thing);
let thing2 = make_big_thing(box_alloc);
do_something_with_thing(&thing2);
}
I see in the crate description that this crate is deprecated. Please consider adding a note to the README describing/linking to a description of why. Is it just unmaintained, or is it no longer necessary thanks to improvements to the Rust standard library, or maybe something else?
I'm not sure if it is appropriate, but can you please replace the license by a more permissive one? For example, MIT or Apache 2.0. I would like to use this library, but the company that I'm currently working at has a policy that forbids MPL license.
Like BoxAllocation
, VecAllocaton
should have an impl Drop
that removes the element that was added if no initialization happened.
Could be done as an optional feature
*** WARNING: ./usr/share/cargo/registry/copyless-0.1.2/bors.toml is executable but has empty or no shebang, removing executable bit
*** WARNING: ./usr/share/cargo/registry/copyless-0.1.2/LICENSE is executable but has empty or no shebang, removing executable bit
*** WARNING: ./usr/share/cargo/registry/copyless-0.1.2/src/boxed.rs is executable but has empty or no shebang, removing executable bit
*** WARNING: ./usr/share/cargo/registry/copyless-0.1.2/src/vec.rs is executable but has empty or no shebang, removing executable bit
*** ERROR: ./usr/share/cargo/registry/copyless-0.1.2/src/lib.rs has shebang which doesn't start with '/' ([warn(missing_docs)])
*** WARNING: ./usr/share/cargo/registry/copyless-0.1.2/rustfmt.toml is executable but has empty or no shebang, removing executable bit
*** WARNING: ./usr/share/cargo/registry/copyless-0.1.2/CHANGELOG.md is executable but has empty or no shebang, removing executable bit
*** WARNING: ./usr/share/cargo/registry/copyless-0.1.2/README.md is executable but has empty or no shebang, removing executable bit
That is creating problems when packaging for Fedora.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.