How much do you guys 'need' statics?
- KVRist
- Topic Starter
- 168 posts since 19 Apr, 2014 from London
I'm currently on a platform without statics of any sort and you cannot call new / delete during during DSP render and I'm wondering how much of an issue the lack of statics is in general.
Personally I and many others can cope, but a static -> scoped transpiler is a potential project of mine.
Personally I and many others can cope, but a static -> scoped transpiler is a potential project of mine.
-
- KVRian
- 1379 posts since 26 Apr, 2004 from UK
static as global variables ? We should not use them anyway.
If we can preallocate the vectors we need (and ensure that you would never callt he DSP code with an array bigger than a given amount), if we have enough room in the stack for temporary variables, I don't see an issue, it's close to what we have to do already.
If we can preallocate the vectors we need (and ensure that you would never callt he DSP code with an array bigger than a given amount), if we have enough room in the stack for temporary variables, I don't see an issue, it's close to what we have to do already.
-
- KVRian
- 1273 posts since 9 Jan, 2006
Well, unless you have large amounts of data and you want to share that data between all instances of a DLL. Image data for example or large wavetables. Stuff like that.Miles1981 wrote:static as global variables ? We should not use them anyway.
But yeah, using static data as a way around allocation during a DSP render/process loop seems like a bad idea.
- u-he
- 28065 posts since 8 Aug, 2002 from Berlin
We use static data for
shared coefficent tables
shared bitmap data
shared preset lists
parameter lists
user preferences
copy/paste among instances
probably much more
We could live without non-const static data, but we can't live without
const static blah something = blahFactory::makeBlah(someCase)
... which may not be allowed where non-const statics aren't
shared coefficent tables
shared bitmap data
shared preset lists
parameter lists
user preferences
copy/paste among instances
probably much more
We could live without non-const static data, but we can't live without
const static blah something = blahFactory::makeBlah(someCase)
... which may not be allowed where non-const statics aren't
-
Zaphod (giancarlo) Zaphod (giancarlo) https://www.kvraudio.com/forum/memberlist.php?mode=viewprofile&u=111268
- KVRAF
- 2596 posts since 23 Jun, 2006
We are using them for
- Shared gui elements
- Shared ir/kernels/data! Pretty everything which is constant and does not change
- Shared gui elements
- Shared ir/kernels/data! Pretty everything which is constant and does not change
- KVRist
- Topic Starter
- 168 posts since 19 Apr, 2014 from London
Thanks for the replies. Just for clarification, I'm working with a particular platform that handles instances differently to typical VSTs, so there is no shared data between instances other than set data files with read only access. Copy / paste is handled by the host and there is no scope for user preferences!
This is the sort of case I imagined being the most common. In short, a static -> scoped transpiler could be lots of fun to write and it's well within my remit, I was just curious to know exactly how people are using and needing it as the word on the street is that it's not commonly needed in DSP (probably because all DSP is done in C right ).
The other use case was the use of smart pointers. Although they'll likely never be deallocated during the lifetime of the plugin, it would be of benefit should the code be used in another context where destruction was going to happen, say test cases or some other different type of usage.
Code: Select all
const static blah something = blahFactory::makeBlah(someCase)
The other use case was the use of smart pointers. Although they'll likely never be deallocated during the lifetime of the plugin, it would be of benefit should the code be used in another context where destruction was going to happen, say test cases or some other different type of usage.
-
- KVRAF
- 3388 posts since 29 May, 2001 from New York, NY
Definitely need them in VIP, as all instances share a ton of things... plugins cache, database cache, UI resources, ....
-
- KVRian
- 1379 posts since 26 Apr, 2004 from UK
I forgot that I'm using lots of static const int as constants (instead of C macro definitions). They should be converted by the compiler as constants, but I'm not sure what the compiler does if it thinks they should be exported.
-
- KVRAF
- 7400 posts since 17 Feb, 2005
Applies a VAT?Miles1981 wrote:I forgot that I'm using lots of static const int as constants (instead of C macro definitions). They should be converted by the compiler as constants, but I'm not sure what the compiler does if it thinks they should be exported.
The preprocessor defines for constants are just parsed as the value in text, so it's no different to writing it as a constant the normal way. The same rules apply for datatype as well.
-
- KVRian
- 1379 posts since 26 Apr, 2004 from UK
There is a difference, which is why I'd rather use static consts than defines: type safety. Another is better compiler messages.
-
- KVRian
- 853 posts since 13 Mar, 2012
Not always.camsr wrote:Miles1981 wrote: Applies a VAT?
The preprocessor defines for constants are just parsed as the value in text, so it's no different to writing it as a constant the normal way. The same rules apply for datatype as well.
static const int MAX_VAL = 5;
..
if (n > MAX_VAL) { ... }
Leads to MAX_VAL being stored on data segment, so the if leads to a cmp n, MAX_VAL_address
#define MAX_VAL 5
..if (n > MAX_VAL) { ... }
Does not add MAX_VAL to data segment, but the if becomes a cmp n, 5
(no clue if recent compiler still act like that, but I think they have to because you actually define that datatype, so it needs memory to store it (unlike with the #define))
~~ ॐ http://soundcloud.com/mfr ॐ ~~
- KVRist
- 347 posts since 20 Apr, 2005 from Moscow, Russian Federation
What compiler? All modern C++ compilers optimize this in release mode...PurpleSunray wrote: Not always.
static const int MAX_VAL = 5;
..
if (n > MAX_VAL) { ... }
Leads to MAX_VAL being stored on data segment
No. Compilers do not have to store any data (even non constant) in memory until you actually use the address of that data (and even in that case it still can optimize a copy of that value to use no memory).PurpleSunray wrote: but I think they have to because you actually define that datatype, so it needs memory to store it...
-
- KVRian
- 853 posts since 13 Mar, 2012
I will check later with current gcc and msvc, but I think this will be hard to optimize.Max M. wrote: What compiler? All modern C++ compilers optimize this in release mode...
What happens if that type is no int, but has a constructor?
What does &MAX_VAL return if MAX_VAL is not on memory, but a compile time constant only? (what's the address of a compile-time defined constant? )
~~ ॐ http://soundcloud.com/mfr ॐ ~~
-
- KVRAF
- 7400 posts since 17 Feb, 2005
Have you tried declaring the static const int inside a struct that is also a class member?PurpleSunray wrote: Not always.
static const int MAX_VAL = 5;
..
if (n > MAX_VAL) { ... }
Leads to MAX_VAL being stored on data segment, so the if leads to a cmp n, MAX_VAL_address
#define MAX_VAL 5
..if (n > MAX_VAL) { ... }
Does not add MAX_VAL to data segment, but the if becomes a cmp n, 5
(no clue if recent compiler still act like that, but I think they have to because you actually define that datatype, so it needs memory to store it (unlike with the #define))
No idea if it's any better, never tried it, but structs are good.
-
- KVRian
- 853 posts since 13 Mar, 2012
Not yetcamsr wrote:Have you tried declaring the static const int inside a struct that is also a class member?PurpleSunray wrote: Not always.
static const int MAX_VAL = 5;
..
if (n > MAX_VAL) { ... }
Leads to MAX_VAL being stored on data segment, so the if leads to a cmp n, MAX_VAL_address
#define MAX_VAL 5
..if (n > MAX_VAL) { ... }
Does not add MAX_VAL to data segment, but the if becomes a cmp n, 5
(no clue if recent compiler still act like that, but I think they have to because you actually define that datatype, so it needs memory to store it (unlike with the #define))
No idea if it's any better, never tried it, but structs are good.
I switched to use unnamed enums like: enum { CONST_VAL1=1, CONST_VAL2=2, }, but it was not really because of statics aded to data segment, but because of the nice 'goodies' of an enum like being unable to use same value twice, auto-completion/intellisense working properly (if that enum is inside a struct), ect pp
~~ ॐ http://soundcloud.com/mfr ॐ ~~