Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
Shorted the title to make it easier for people to understand the problem.
When I've finished adding data to an array, I need to open Activity Monitor and close two processes (Swift and SourceKitService).
Because of the array, Swift and SourceKitService use all available RAM and they have to be closed.
How can I keep adding to the array in the swift file without having to continually close processes?
The Swift compiler is probably getting tied up in knots because your array is long AND it can’t determine the type so needs to rely on implicit checking which is expensive.
The longer the array the bigger the problem.
You may need to provide an explicit type to your declaration.
E.g
let foo: [String] = [“boa”,”fool”,”zoo”,...
Vs
let foo = [“boa”,”fool”,”zoo”,...
Whatever the type of the array elements you should declare this explicitly to assist the compiler when you encounter this issue.
Yes, it should just work, but this is real life and the Swift compiler is young.
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I had some fun with imitating OOP in C, but I got somewhat discouraged when I understood that I'll have to call member methods like obj->method(obj, ...). Then I thought about cloning and modifying functions at runtime. Can I implement a function like strdup but for functions using a simple parser to identify the return opcode to stop copying and then modify a value in the function to point to the object the member method refers to so that I can use just obj->method(...)?
No, at least from what it sounds like you are asking, which is to modify functions at run-time. Modifying functions at run-time is possible but is difficult and requires considerable knowledge (and is system-specific). However, you seem to be asking to be able to execute a function and modify the function so that it does something with the object it is associated with. However, by the time the function is executing, there is generally no information about that object available: In a call like obj->method(…), there is generally no reference to obj included in the arguments. So even if you could modify the function at run-time, it does not have the information needed to do the job you want.
There are ways to do it at compile-time. That is how C++ developed. If that is a feature you want, the best approach is to use C++.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I'm currently working on a system where features are enabled by a database check.
if(feature_db(id)) {
//new logic
else {
//old logic
}
I want to replace this with a MACRO.
FEATURE_ENABLE(feature_db, id)
//new logic
FEATURE_DISABLE
//old logic
END_FEATURE
I want to do this because it becomes more clear where these occur and its more explicit what is happening. I want to know if there is just a general more elegant way to to do this?
No, your resulting code is less clear for any competent C programmer: C programmers know about if and function calls. They do not know about the syntax and semantics of your custom macros that do not follow general convention. As a consequence, they first need to discover what the macros do, and ensure that using them in this way is in fact correct and safe — neither of which is obvious from your code.
However, you can make your initial code clearer by naming the function better and adjusting its parameters, e.g.:
if (feature_enabled(feature_db, id)) {
…
} else {
…
}
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
So lets say I have received a message that resembles the following
"L2N5*8R10!11T0A1K3Y14#4W7O6O9C12R13"
and I am expected to sort out the characters in accordance to the numbers succeeding them and change the characters that are not letters into a space. I have no problem doing the sorting out part, I am only having a trouble while trying to write a function that will change those characters into space.
The out put should be something like this
TALK NOW OR CRY
but I am getting
TALK#NOW*OR!CRY
Can anyone help me figure out what my function should look like so that I can be able to change the characters into space??
Unless you show your code, we'll only be able to guess!!
However, as a general suggestion, I would recommended, you should check each entry against isalpha(). In case you got a return value of 0, replace the entry with a .
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Why do we use pointers in C Programming?
In general pointers are able to access the address where the int/float/char etc... is stored.
Are there any other uses?
It depends on what you try to achieve:
you can change the value of a variable inside a function
you can pass a struct to a function without having to copy all its fields - think of a function that receives a struct.
you can point to a specific variable/struct and point to it from other structs
and many other advantages (advantages is purpose dependant and it depends on whats your program is doing).
Pointers are quite basic C and there is a lot of material online you should get yourself familiar with them and the advantages will pop up themselves.
The reason is that pointers are used to bodge into C some vital features which are missing from the original language: arrays, strings, & writeable function parameters. They can also be used to optimize a program to run faster or use less memory that it would otherwise. A few tasks these days, such as programming microcontrollers, still need this.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am BRAND NEW to Matlab (like, 5-minutes ago new). I need it to read some files that I have because no other program can read them. I was hoping someone could help me understand some basic matlab so that I can accomplish this. I need to go through every file in a folder and perform the function
X = multibandread(filename, size, precision, offset, interleave, byte order)
on each file. (X is an array and I need to make a different array for each file). To further complicate things, the size argument to multibandread is a 3-element vector of [height, width,N], and I'd like to get the height and width values from other files. i.e:
[size(other_file, 1) size(other_file, 2) 2].
So, I'm still very much trying to understand matlab. It seems like a powerful type of command prompt that I can write programs into? Is that accurate? Is there a way to point to each file in my program, call multibandread on it, and then move to the next file?
I know some C programming but know absolutely nothing about matlab.
Thanks for any help or really any general matlab education anyone can give!
Use the inbuilt Matlab dir command and a simple loop:
myFiles = dir('c:\MyFolder');
% Now loop through the files.
for k = 1:numel(myFiles)
X = multibandread(myFiles(k).name, size, precision, offset, interleave, byte order);
end