|
If this is connected to your question below, it is possible that the system available on the embedded device did not include a full standard C library. Alternatively this could just save using the library and thus reduce memory requirements.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
Thanks, but according to the compiler manual:
//the compiler include the standard set of C library functions.//
I think which means the standard C function like memcpy should be accepted by the MCU, and the compiler is specific fot the MCU family.
|
|
|
|
|
Perhaps the library implementation is less efficient, you could look at the disassembly of the library memcpy() to find out. Or as Richard pointed out, maybe the person didn't want to deal with memory requirements of using the library.
|
|
|
|
|
Well, as I said before you are showing us a few lines of code and asking why it is done this way, but we do not have any information on the implementation of this product. You need to talk to the people who wrote this and ask them why they did it this way.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
econy wrote: I wonder why the coder didnot use standard C memcpy functio
1. They didn't know it existed.
2. The 'volatile' is important.
3. They thought 'volatile' was important. Perhaps due to the source of the pointers being passed.
4. They are doing a lot of very small copies and the compiler will optimize those with a user method but will not do so with a library method (it will always call the library method rather than attempting to unroll it.)
5. memcpy returns a value, the method doesn't. Perhaps that was important in terms of stack space.
6. The code was originally written with a very early version of the compiler and memcpy was buggy. Or the coder thought it was buggy. No one has challenged that since then.
Could also be a combination of the above.
|
|
|
|
|
For very small copies, this may be faster since it doesn't bother looking at alignment. However, if intrinsics are enabled, many compilers will identify the code as a copy and use an intrinsic instead (an inline memcpy.)
(See previous comment. Also note that years ago, especially for very small memory usage, many embedded developers wouldn't use the CRT; they wouldn't use libraries of any kind. This wasn't arrogance, but that they had to control every aspect of the code. Even today, I deal with many serious problems where third party libraries are used, including STL and Boost.)
modified 7-Jan-13 16:32pm.
|
|
|
|
|
Hi, I am reading a program, found a code block like the following:
for (i=0; i<16; i++) { Bstruct.aa[i] = Btable.aa[i];}
for (i=0; i<16; i++) { Bstruct.bb[i] = Btable.bb[i];}
...
for (i=0; i<16; i++) { Bstruct.kk[i] = Btable.kk[i];}
This is a embedded program running on a MCU.
I wonder what is the benefit for the usage of the for loop like above.
|
|
|
|
|
In this particular case I don't see a real benefit for seperating the for loops, perhaps the author thought it to be easier to read? However, if there comes a time when Bstruct.aa[]/Btable.aa[] has a different number of entries than Bstruct.bb[]/Btable.bb[] then this would be easier IMO to maintain.
|
|
|
|
|
All Bstruct.aa[],bb[] ... kk[] have the same size 16.
Is there some cons for using seperate for loops? the compiler maybe optimized them in one loop in assembly?
|
|
|
|
|
econy wrote: All Bstruct.aa[],bb[] ... kk[] have the same size 16
Yes, today they do, tomorrow, who knows?
econy wrote: Is there some cons for using seperate for loops?
Using more CPU cycles because of the multiple initializations and testings (some MCUs clear thier cache when branches are executed) of i. Other than that I can't think of any.
econy wrote: the compiler maybe optimized them in one loop in assembly?
Don't know offhand, my gut tells me they wouldn't be optimized out.
|
|
|
|
|
|
This would depend to some extent on the target hardware and the program design. The only way to be certain would be to ask the original writer.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
No benefit, in my opinion.
Veni, vidi, vici.
|
|
|
|
|
The key is "embedded". Some CPUs, many in the embedded space, throw exceptions for misaligned data access EXCEPT for byte access. This is one way to copy data with unknown alignment (say from a socket or file) to an aligned data structure. (The original ARM chips would throw an exception, which some embedded OSs would catch and then do exactly the above internally.)
|
|
|
|
|
I need to display 8 roads video at the same time.
But I find that the DrawDibDraw is too slow, it need 16ms to draw one frame data.
it nearly cannot be accepted.
Then I try to use the directdraw to draw the YUV data to windows, but I cannot get a right answer after google half a day. Is there some one know how to draw the YUV or RGB data to a form using the directdraw? thanks.
|
|
|
|
|
As is known to all, unicode can represent all the character in the world. Now, my problem is how to create font by an unicode value. Because each unicode value represents a char.
Here is a related link: http://www.ssec.wisc.edu/~tomw/java/unicode.html[^]
Here is a C++ API:
HFONT CreateFont(
_In_ int nHeight,
_In_ int nWidth,
_In_ int nEscapement,
_In_ int nOrientation,
_In_ int fnWeight,
_In_ DWORD fdwItalic,
_In_ DWORD fdwUnderline,
_In_ DWORD fdwStrikeOut,
_In_ DWORD fdwCharSet,
_In_ DWORD fdwOutputPrecision,
_In_ DWORD fdwClipPrecision,
_In_ DWORD fdwQuality,
_In_ DWORD fdwPitchAndFamily,
_In_ LPCTSTR lpszFace
);
Is it possible to do that by the function?
Anyone can help me?
|
|
|
|
|
The CreateFont [^] function creates a logical font based on the request parameters and the actual font files that are loaded on your system. Most fonts include Unicode characters for various different languages and there are fonts that handle Asian type alphabets.
Creating a new font from scratch requires a number of other tools; Google will help you to find articles on the subject.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
dear all,I have a question,when I write files,like pdf,i want to popup a dialog with animation to show
that the writing operation is working.
I don't know how to do with that ,it may need a avi file ,use CAnimateCtrl,is it need multithread,please
help me.this is my code
void CMainFrame::OnExportPdf()
{
CExportPro* ExPro;
ExPro = new CExportPro();
CFileDialog dlg(FALSE,TEXT("txt"),NULL,OFN_HIDEREADONLY|OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST|OFN_OVERWRITEPROMPT,_T("TXT (*.txt) |*.txt|"));
CString fileName;
CString filePath;
if(dlg.DoModal()==IDOK )
{
ExPro->SetCaption(TEXT("pdf"));
ExPro->Create();
ExPro->ShowWindow(SW_SHOW);
filePath = dlg.GetPathName();
m_filepathname = dlg.GetPathName();
if ( !filePath.IsEmpty())
{
CFile file;
CString str(TEXT("hello this is the test for write process"));
file.Open(filePath.GetBuffer(),CFile::modeCreate|CFile::modeWrite);
while (i<1000000)
{
file.Write(str,str.GetLength());
i++;
}
file.Close();
}
}
}
BOOL CExportPro::OnInitDialog()
{
CDialogEx::OnInitDialog();
SetWindowText(m_StrCaption);
m_avi.Open(IDR_AVI1);
m_avi.Play(0,-1, -1);
return TRUE;
}
I know It is not my means,but how can do ,when writing it display avi.
|
|
|
|
|
Where exactly are you stuck?
Perform all your file writing operations in a background thread, and compute and post messages on the operation progress from the worker thread to your main window. Your main window procedure should handle this message and display the progress accordingly.
"Real men drive manual transmission" - Rajesh.
modified 4-Jan-13 6:20am.
|
|
|
|
|
Thanks,but I use CAnimateCtrl,this is a control,I initial it in dialog CExportPro::OnInitDialog(),I think
when modalless diaolog appear,the control should be appear ,but the fact is that when writing it appear modalless diaolog without CAnimateCtrl,and after writing,the CAnimateCtrl show,why,it maybe the thread
hang_up.how to do with it.
|
|
|
|
|
My current task is to develop C/C++ project for running on Linux (Ubuntu). My Windows PC has Visual Studio Express, Eclipse and Cygwin installed.
I have worked with C/C++ on MS Windows years but I am new to the situation above.
Could anyone help me to configure and show me step by step how to create and build a project (I need to work
all on MS Windows 7)?
I mean how to develop C/C++ project on Windows environment described as above and the built file can run on Linux.
Thanks in advance.
|
|
|
|
|
|
You cannot run Windows unmanaged programs on Linux. You can do the base development as long as your code is POSIX compliant, but you would be better getting access to a Linux system and using the Linux development tools.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
People, I met a rather strange situation. I deleted a small memory block and after it was not able to allocate another one. Operator "new" presented me with "out of memory" exception. But without previous call of "delete" "new" gave me what I asked it for (I'm talking about small blocks, something like 10KB). At that very time VirtualAlloc() successfully allocated required memory. How could it be?
|
|
|
|
|
Corrupted heap springs to mind.
|
|
|
|