A little experience of DSP learning-----Memory Management __ Optimization

Source: Internet
Author: User

1. Would like to create a large array in a function, the function is automatically deleted, but it is not possible, this large array is best declared as a global variable, and save it to the external extended memory, do not let it occupy a limited memory on the chip, otherwise the program is very easy to run. C language itself is relatively good to run flying phenomenon, and because of memory problems and run, very secretive, difficult to check.

Statement deposited on the expansion of the film: #pragma data_section (G, ". G ");

Then write in the. cmd file:. G > CE0

Or you can change it. Stack, put the whole stack to CE0. But this can seriously slow down the system. Do not believe that the extended memory is faster than the memory on the chip.


2. The name of the general array represents its first address, but there are some awkward places in CCS.

If the array g is declared in another file, the words you want to use in this file are directly extern int G; But to use a pointer to point to this g, such as: G_pointer to point to G, it should be written as a g_pointer=&g; if written g_pointer=g, will be prompted with an error.

If G is a static variable defined by this file, point to it with a pointer, it can be written as: g_pointer=g;


3. The necessity of assigning a large array as a static variable and allocating memory space to it independently:

If a large array is defined inside a function, its data can be inexplicably abnormal and will change frequently. In fact, it is not the fault of your program, is the reason of memory, so bite the bullet, put them all to the program ahead.


4. printf in the program does not work:

Of course, it's a memory problem. Online only one by one related articles said is-heap, let the heap into 0x400, my heap is 400, then changed to 800 also useless. After moving the. Stack to the outer memory, printf works, and the change in option stack to 800 is useless.

Do not change. Stack is OK, change the stack in option to 0x1000,heap or 0x400,printf can be used.

Like the LDPC so consumes more memory of the program, the best stack set into 0x3000,heap do not care about it.

The stack size is wrong or put on the CE0, all may cause the program result error, is in the memory accesses the unconscious rewriting, the concrete reason and the countermeasure waits for the analysis.


5. Without the board comrades do not do, light on the PC on the simulator too slow, not too realistic.


6. An array of external static variables that are used in the calling function, as other files have already been defined, must be invoked with pointers and do not support the form of g[].

However, if the G is defined in this document, it can be used g[]. The definition G time seems to add static, call can use g[], do not know that there is no static line.


7. C There is also a use of far defined variables, not used, do not know how to use, do not know what the advantages of using, please advice. Check the. map file, which shows that static numbers exist. Far, perhaps CCS will automatically identify far and near variables.

There is also a question of what the memory alignment: #pragma data_align (Highpoint, 8), as if the effect is not the same, why should be aligned AH.


8. For CCS, for the external variable G, the initialized statement int g[100]={0}; does not change the element of G

into 0, so be honest with the Memset statement to initialize it.

However, it is possible for dynamic variable {0} to be initialized.


9. VC in a pointer is unsigned int or int type are indifferent, means that the pointer + 1 jump 4 bytes, but CCS is very strict, g if it is unsigned int, his pointer must be defined as unsigned int *.


10. Declarations of different documents: each document in CCS is to be declared, as file a requires include <stdio.h>, and file B is required, a,b two files are written with include <stdio.h>, and the compiler will not automatically find them. Also includes:

#define ..., #pragma data_align and other statements.


CCS's printf does not work very well, such as printf ("%f,%d", a,b), then B will display an error, showing an inexplicable value, so apply printf on CCS to a variable with a pirntf. It is also useless to modify the stack size.


12. If the program uses an array that is very large (as is often the case with the communication program), the relocation value truncated 0xxxx in section. Text, file will appear when compiling to the last link. The general approach is to declare a large array in a specific memory space, stating that it is stored on a film that expands: #pragma data_section (G). G ") If this does not work, modify the build option, into the advance, the memory mode into the" far ", the RTS calls to" are far "on the line.


13. Need to be very careful: CCS has an automatic optimization function, that is, choose-o1~-o3 in Build option, there will be different degrees of optimization results. But after optimization, CCS will turn the loop of the program into a DSP-like pipelined form, so it's unwise to debug programs with optimized programs, because your loop variable counter will no longer show its original value, and when you step into it, you're probably not going to follow the procedure one step at a time, Because optimization can bring a program jump. So the correct way is, in the debugging phase of the program does not optimize, debug successfully, the results are correct, and then optimize. The optimization effect is very obvious oh.

14. May 7, 2011, today a very simple program on the DSP to run away, do not know how. The final discovery is the problem of the header file, not without the header file, but the header file definition too many times. I put all the header files and statements into a config.h file, which used ifndef, endif, and other pseudo instructions, in all C programs include this header file, the problem is solved. Start to think this kind of writing is a simple refining of the writing, did not expect to prevent the role of DSP running, it seems to be a standard way of writing.

Note: After a few days found that the 14th problem of this solution is only superficial, its essence is the FP = fopen () in CCS, the function, CCS does not support the file processing function here very well, often have problems, including the 15th question. And what's even weirder: when I annotate these file-handling functions, the program still flies, and the annotated program is removed, and the program works, which means that functions such as fopen () are still affected by the process of CCS even if they are commented out, which is true.

15. The fprintf operation of CCS, the output of a text it is very strong, it may not be able to save text. Then we need to be clear about the size of the-heap (heap) since the text was saved in CCS, which can be resolved by changing the size of the heap from the default 0x400 to 0x700 or 0x1000 in Build option.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.