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

Flyweight pattern #8

Open
AndrewCarterUK opened this issue May 12, 2016 · 1 comment
Open

Flyweight pattern #8

AndrewCarterUK opened this issue May 12, 2016 · 1 comment
Labels

Comments

@AndrewCarterUK
Copy link
Contributor

Should the flyweight pattern be used (so that there is only ever one instance of any pin as they are remembered by the factory)?

For

  • Reduces memory
  • Increases performance (especially if pins auto export or configure on construction)

Against

  • Memory and performance differences could be insignificant
  • Might make it more difficult to switch a pin from an input to an output pin. Primary key would have to be number + direction rather than just number.

Again - interested to hear thoughts?

@colinodell
Copy link

so that there is only ever one instance of any pin as they are remembered by the factory

That makes sense to me since only one instance of the physical pin exists anyway. I'm not yet convinced it's totally necessary (will have to think on this) but it certainly seems useful.

Might make it more difficult to switch a pin from an input to an output pin. Primary key would have to be number + direction rather than just number.

I honestly don't think this will be very common. If you really need a pin to read and write data at different times you should probably be using a protocol like I2C, SPI or 1 Wire which can coordinate that switching with the other component(s) you're wired up to. And I think Raspberry Pi handles those with kernel modules separate from GPIO (unconfirmed).

Because I personally wouldn't be switching pin modes in my projects, I don't have a strong preference on how it handles people creating input and output pin objects for a single physical pin - it can either allow it or throw a big exception for all I care :)

Memory and performance differences could be insignificant

I wouldn't be too worried about the memory footprint of the objects themselves, but could having so many streams cause performance issues? If so then I think a flyweight could definitely help there.

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

No branches or pull requests

2 participants