-
Notifications
You must be signed in to change notification settings - Fork 27
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
Remove memory_id requirement #89
Comments
The problem you're describing sounds more of an architectural problem to me. The memory manager, should one choose to use it, is a global resource. IMHO dependencies shouldn't be using global resources directly, since you'll run into conflicts just like the one you're describing. Instead, a more resilient architecture is for dependencies to ask for resources from the user. In the above example, the dependency should initialize itself with three empty memories, specified by you, so that you can avoid these clashes. This clash isn't specific to the memory manager. It equally applies to all other global resources, like stable memory and timers. As for dropping the memory ID requirement, on first thought, I'm not sure how that can be done. When you declare a stable structure, there are two scenarios in which the stable structure is initialized:
When you specify the memory explicitly, as you currently do, it's clear to the stable structure which memory to look at, but if memory ID is somehow implicit, then it's not clear to me how we can distinguish between these two cases. Ideas on how to resolve this problem would be very welcome. |
I agree with @lastmjs . Using memory_id, for application developers, exposes too many underlying details. Application developers should spend their energy on [how to build a good application] instead of spending more energy on [underlying storage management details] |
As I mentioned above, there are technical reasons why we haven't been able to do so. We're of course happy to incorporate concrete technical suggestions you have that address the problems I laid out above. |
I will be digging into this, I hope I can come up with some ideas. |
What if we added Then against each object that you wish to store in stable memory you could have an If it is |
But then the memory id would be based upon the position or order of the stable structures being initialized right? If the dev decided to move a map somewhere else in the code, I could see them easily messing up the order. |
I think libraries that use this crate should simply always take the memoryIds as inputs then everything can be controlled by the devs of the main app. |
I don't understand the suggestion. Can you share an example? Let's say you have the following code:
If we replace the actual memory IDs with calls to |
My suggestion was to keep using |
Agreed, libraries should be passed in memories explicitly and not use specific IDs themselves. |
Requiring a memory id is not desirable, as it adds complexity to the creation of stable structures. I just ran into an issue where a dependency of my application was also using stable structures under-the-hood, and it had decided to use memory_ids 0, 1, and 2. My application of course was also using these memory ids. We had a clash, thus I had to figure this out by looking through source code, and eventually I changed my own application.
Not an ideal situation, and these clashes and issues I imagine will get more painful over time.
The text was updated successfully, but these errors were encountered: