forked from jsoref/imageflow
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace use of flow_context_calloc/destroy with AllocationContainer
- Loading branch information
Showing
10 changed files
with
106 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use crate::graphics::aligned_buffer::{AlignedBuffer, AlignedBufferError}; | ||
|
||
pub struct AllocationContainer{ | ||
allocations: Vec<AlignedBuffer<u8>> | ||
} | ||
impl AllocationContainer{ | ||
|
||
pub fn new() -> AllocationContainer{ | ||
AllocationContainer{ | ||
allocations: Vec::new() | ||
} | ||
} | ||
/// Allocates the specified number of bytes with the given alignment and returns a pointer | ||
pub fn allocate(&mut self, bytes: usize, alignment: usize) -> Result<*mut u8, AlignedBufferError>{ | ||
let mut buffer = AlignedBuffer::new(bytes, alignment)?; | ||
let ptr = buffer.as_slice_mut().as_mut_ptr(); | ||
self.allocations.push(buffer); | ||
Ok(ptr) | ||
} | ||
/// Returns true if the pointer was found and freed. | ||
pub fn free(&mut self, pointer: *const u8) -> bool{ | ||
match self.allocations.iter() | ||
.position(|a| a.as_slice().as_ptr() == pointer) { | ||
Some(index) => { | ||
self.allocations.remove(index); | ||
true | ||
}, | ||
None => false | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
|
||
#[derive(Debug, Clone)] | ||
pub enum AlignedBufferError{ | ||
SizeOverflow, | ||
InvalidAlignment, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters