Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accessing storage via Pointer #7

Open
vitvakatu opened this issue Apr 20, 2017 · 6 comments
Open

Accessing storage via Pointer #7

vitvakatu opened this issue Apr 20, 2017 · 6 comments

Comments

@vitvakatu
Copy link
Collaborator

At this moment there is no way to access Storage from Pointer to that Storage, despite Storage is still in memory.
For example:

let storage = Storage::new();
let ptr = storage.write().create(10 as i32);
drop(storage); // storage is dropped, but stand in memory, 
// because there is Pointer that points at it.

I suggest new method for Pointer, that will return Storage pointed by it

@kvark
Copy link
Owner

kvark commented Apr 20, 2017

After a bit of elaboration on Gitter, we decided to not expose it. Leaving the issue open for further discussion.

@vitvakatu
Copy link
Collaborator Author

It's no more possible with current implementation (see #25)

@kvark
Copy link
Owner

kvark commented May 17, 2017

I'm thinking if something like this would be feasible:

struct FatPointer<T> {
  pub storage: Arc<spin::Mutex<Storage<T>>,
  pub pointer: Pointer<T>,
}

With this, we could have helper methods (even Deref?) to access the data directly, provided that everything would need to keep Arc<Mutex<Storage>>. Special care needs to be taken of possible deadlocks (which are inevitable).

@kvark kvark reopened this May 17, 2017
@vitvakatu
Copy link
Collaborator Author

Do we really need it?
Well, it can be useful in some scenario, but if we mix FatPointers with the regular ones, it will have no sense - you'll still need Storage.
Using FatPointers alone is better, but the performance will be awful
And avoiding deadlocks will be extremely tricky.
All in all, I'm not against, we just need to investigate this topic and act carefully.

@TyOverby
Copy link

As a casual observer (I'm planning on using Froggy at a later date), I mostly take issue with the name. I'd replace it with MutexPointer so that they know just how bad of an idea it is.

That said, I think that if people use these, there's going to be a lot of wasted time dealing with deadlocks.

@kvark
Copy link
Owner

kvark commented May 17, 2017

yeah, I agree completely. Just don't want to take the idea off the table just yet. See, the (original) promise of Froggy was that you can work with it as having a regular OOP program. Forcing the user to always have Storage available when they need to use a pointer makes it not quite OOP. Having an option of FatPointer would potentially solve that, if only we can make it work without dead-locking.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants