|
I would suggest you need a better understand of threads, and some practical experience of using them. Without understanding the basics, I doubt that OpenMP is going to bring you any benefit.
|
|
|
|
|
No, threads and processors are not related in any way. Processors (CPUs) are hardware, threads are pieces of code that run in a CPU. An application can create as many threads as it likes regardless of how many processors exist in the system that it runs on. In most cases you do not need to know how many CPUs are available, since your application should be based on its business/technical design rather than the hardware it runs on. Finally, do not assume that you can control how many processors your application uses; the operating system is in control of resources, and allocates them as necessary.
|
|
|
|
|
Need c coding for the below scenario
Case 1: Input: string 1: -(a+b+c)
String 2: -a-b-c
Output: True
Case 2: Input: string 1: -(a-b)
String 2: -a-b
Output: False
|
|
|
|
|
Post what you have tried and try to ask specific question(s). You're not likely to find someone that will just write it for you.
"the debugger doesn't tell me anything because this code compiles just fine" - random QA comment
"Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst
"I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle
|
|
|
|
|
Hint count the minus signs in your expanded string
In vino veritas
|
|
|
|
|
|
This is just curiosity , not a question.
I code in C++ , using IDE.
It "builds" the executable using "make" without me messing with "automatically generated" "make" by IDE. Accessing the "make " sometime warns that is it so generated by IDE and not to modify it.
Most of the time I follow instructions, so I let IDE to do its stuff.
I have noticed that some code posts here include manually building the "make".
Why if run of the mill IDE does it "automatically" ?
I am sure there are occasions when IDE generated make could use some tweaking, but in general IDE does the job well.
Off soap box.
Cheers
Vaclav
|
|
|
|
|
It is the same as the compiler. You can let the IDE set the options and generate the command, or you can run it yourself in a command window. Programs such as cl (the C/C++ compiler), make etc., have existed for years, long before the IDEs were developed. The IDEs just try to make life easier for you. I have a Visual Studio project that does not run the standard way so I had to create my own Makefile to build it. You are free to do that with any of your projects if you want greater control over how they are built.
|
|
|
|
|
Vaclav_ wrote: I have noticed that some code posts here include manually building the "make".
Why if run of the mill IDE does it "automatically" ?
Your IDE probably creates the Makefile from some sort of project database, perhaps a .proj file. Lets assume that I create a library that you would like to use, but I use a different IDE than you, which uses Project.DB files that are completely different than the .proj files your IDE uses. If my project creates a Makefile that can be used from the command line, then you don't have to figure out how to import and build the library using your IDE, or how to install and use the IDE I use. Additionally, your IDE might clobber the Makefile distributed with my project, in which case you're going to have to go try to make sure you've got all the dependencies right, which might take a lot of time.
In the land of UNIX like OS (Linux, BSD, Darwin, etc), make is almost ubiquitous. If the OS doesn't ship with make, someone will probably have a version of make (e.g. gnu-make) available. That means make is, more or less, the de facto build tool.
|
|
|
|
|
The answer to that is historic most of the original C compilers were around with DOS and Unix all we had was a command line. So on the command line you used to have to type these extremely long strings and so everyone wrote DOS batch files or unix shell scripts. Come 1976 and make was created by Stuart Feldman and it was released to public domain.
Make never really took off with DOS users as by 1983 Windows 1.0 was released and a small company called Borland began with Pascal and later C as a text GUI on the windows platform.
Borland - Wikipedia[^]
Microsoft saw the success of Borland as a threat (they used DOS command line in house) and essentially began to mimic Borland at least on the GUI (the compiler remained a dos executable) and thus was born the first microsoft compiler tools.
With no big bucks for GUI compilers being spent on linux make became a staple thing for the linux OS. Even most embedded compilers tended to stay as DOS or Windows with a couple of exceptions. So generally you could pick Windows versus Linux developers by did they know there way around make which developed it's own language.
More recently GUI compiler IDE's started to pop up in linux and so they will import and work with Make files. Windows Visual Studio now can even work with make files as it is targetting linux developers although in all honesty they would like them to move to CMake.
There is also a very subtle difference between windows and linux repositories because of the history that many linux programmers fail to notice. Most windows code has the header files for the C code files in the same directory, on most linux repositories you will find all the headers in an include directory (they seem to view it is good practice) and the source files elsewhere. The reason for the difference is Windows compilers have a specific search order which is same directory as C file, library directory and then user defined include directories. Under windows compiling #include <some.h> is very different to #include "some.h" (the first means the C system directory the second means the user defined directory) on linux repositories that difference always seems to get lost (all the code is pubic domain none is company copyrighted) they randomly they use either -l or -L and fix it in the makefile. Under Windows you start messing around with the system directories you will get in a world of hurt (as much is precompiled copyrighted) and usually only SDK's do that.
In vino veritas
modified 7-Feb-19 23:34pm.
|
|
|
|
|
leon de boer wrote: all the code is pubic domain I now have a most strange image in my mind ...
|
|
|
|
|
Quote: I have noticed that some code posts here include manually building the "make". Why if run of the mill IDE does it "automatically" ?
Possibly because I am not using an IDE .
|
|
|
|
|
|
baid is a IDE , bash is a shell .
|
|
|
|
|
I'm working on a music notation program, where it needs to be possible to select any object, like a note or a clef, by clicking on the glyph. In order to determine whether a glyph has been clicked, I'm trying the approach of iterating through the drawable objects, rendering them each into a memory device context with a blank bitmap selected, mapping the mouse coordinates into this bitmap, and checking whether the pixel they map to is filled.
While I'm getting this system working, I'm rendering a rectangular frame with the dimensions of the memory device context's bitmap to the corner of the window, and rendering the bitmap itself into it using BitBlt in order to see what's going on. What I see surprises me. I thought that rendering a glyph into the memory device context using TextOutW with x = 0 and y = 0 would put the glyph's origin at the top left of the bitmap, like it does when rendering to a window in the most basic case. Instead, the glyph appears to the left but vertically centered in the frame. So...given that the bitmap handle I selected into the memory device context was created using CreateCompatibleBitmap with cx = w and cy = h, does TextOutW treat it as having a coordinate system where x ranges from 0 to w while y ranges from -h/2 to h/2? Is there somewhere on MSDN that discusses this?
|
|
|
|
|
I might not be getting the full scope of your question but since you are drawing the glyphs
into I assume 'known' rectangle area, could you not use CRect::PtInRect() to test if you hit a glyph area?
|
|
|
|
|
I want the clickable area to be exactly the pixels that are part of the glyph, rather than anywhere in a bounding rectangle that contains the glyph. There are situations where music symbols nest together, or where parts of one are visible through the gaps in another. Using single rectangles for each would count one as obscuring parts of the other even though those parts are visible - any part that's visible should be clickable. I could define a set of bounding rectangles for each glyph in order to approximate them more tightly, but that's a lot of work I'd rather not do unless it turns out that the method I describe is too slow.
|
|
|
|
|
You are dealing with TTF glyphs not a bitmap and you will need to understand how FUnits and the EMSquare work
TrueType fundamentals - Typography | Microsoft Docs[^]
The glyph is rendered to screen it never is a bitmap.
Now what you could do if font style isn't important is select a bitmap font and it will work much as you think.
Now if you want to do what you are doing with a TTF the function you want is called
GetGlyphOutlineA function | Microsoft Docs[^]
The DC will be your window you are drawing the text on so it matches one to one.
Now the problem is you will have an outline with beziers and lines and to be able to decide if you are in or out you need to scanline the contour at the y value and see if the point is between any two runline points of the scanline. Now if you follow all that this is the two scanline functions you need
short ScanlineLine2D(long x1, long y1,
long x2, long y2,
long sy,
long* px1){
long xt;
double t;
if (y2 == y1) return (0);
if (((sy >= y1) && (sy <= y2)) || ((sy >= y2) && (sy <= y1))){
t = ((double)(sy-y1)-FLT_EPSILON)/(double)(y2-y1);
if ( (t >= 0.0) && (t <= 1.0)) {
xt = (long)((double)(x2-x1)*t) + x1;
if (px1) (*px1) = xt;
return (1);
} else return (0);
} else return (0);
}
short ScanlineQuadBezier2D(long x1, long y1,
long x2, long y2,
long x3, long y3,
long sy,
long* px1, long* px2){
short rslt;
long dx0, dy0, dx1, dy1, dx2, dy2, xf;
long* px;
double tmf, tdf, tf, ymf;
dx0 = x2 - x1;
dy0 = y2 - y1;
dx1 = x3 - x2;
dy1 = y3 - y2;
if ((dx0 == 0) && (dy0 == 0) && (dx1 == 0) && (dy1 == 0))
return (0);
if ((dx0 == 0) && (dy0 == 0))
return (ScanlineLine2D(x2, y2, x3, y3, sy, px1));
if((dx1 == 0) && (dy1 == 0))
return (ScanlineLine2D(x1, y1, x2, y2, sy, px1));
dx2 = (dx1-dx0);
dy2 = (dy1-dy0);
if (dy2 != 0){
tmf = -(double)dy0/(double)dy2;
ymf = (double)y1 + FLT_EPSILON + tmf*(double)dy0;
tdf = ((double)sy - ymf)/(double)dy2;
if (tdf < 0.0) {
return (0);
} else if (tdf != 0.0) tdf = sqrt(tdf);
rslt = 0;
px = px1;
tf = tmf - tdf;
if ((tf >= 0.0) && (tf <= 1.0)){
xf = (long)(((double)dx2*tf + (double)(dx0*2))*tf) + x1;
(*px) = xf;
rslt++;
px = px2;
};
tf = tmf + tdf;
if ((tf >= 0.0) && (tf <= 1.0)){
xf = (long)(((double)dx2*tf + (double)(dx0*2))*tf) + x1;
(*px) = xf;
rslt++;
px = px2;
};
return (rslt);
} else if (dy0 != 0) {
tf = ((double)(sy - y1) - FLT_EPSILON)/(double)(dy0*2);
if ((tf >= 0.0) && (tf <= 1.0)){
xf = (long)(((double)dx2*tf + (double)(dx0*2))*tf) + x1;
(*px1) = xf;
return (1);
} else return (0);
} else return (0);
}
In vino veritas
|
|
|
|
|
I was actually able to make what I originally had in mind work - I know the glyphs aren't *defined* as bitmaps, but rendering a glyph into a device context with a bitmap selected effectively makes it into it into a bitmap, and that's what I did - but analyzing the glyph outlines directly as you suggest is surely more efficient, so I'll probably try it too.
|
|
|
|
|
Throw me an email to my personal account if you need a help. I have a pile of code for this stuff from CNC programs I have worked on for filling and inline/outlining the TTF fonts.
In vino veritas
|
|
|
|
|
The reason the location of the glyph in the memory device context bitmap wasn't what I had expected was that I had long ago set the text alignment of the window device context to TA_BASELINE, but that of the newly-created memory device context was set to something else.
|
|
|
|
|
Hi all,
I've had some preview on VS2019. They implemented a new feature, which places the application menu onto the title bar. Any thaughts on how to get this in an MFC application, too?
Regards,
Franz
|
|
|
|
|
Hi all
I have an MFC application that works perfectly with the CMDIChildWnd class, the frame is loaded and a splitterwnd is shown. I needed to create a new MFC application that uses the ribbon as the interface, and for that the only change I made was that my classes inherited from CMDIChildWndEx.
The two MFC applications should work with CMDIChildWndEx, but the old application does not show anything in the frames, it does not show errors, exceptions, it does not show inside the window. I already tried changing the style, forcing the frame size, changing the spliterwnd but nothing worked. See the LoadFrame code:
<pre lang="c++">void CMyFrame::ActivateFrame(int nCmdShow)
{
if (m_pMDIFrame && m_pMDIFrame->SendMessage(WM_IS_ENABLE_MDI_TAB))
{
LONG style = ::GetWindowLong(GetSafeHwnd(), GWL_STYLE) | WS_MAXIMIZE;
style &= ~WS_BORDER & ~WS_THICKFRAME & ~WS_DLGFRAME & ~WS_CAPTION;
::SetWindowLong(GetSafeHwnd(), GWL_STYLE, style);
style = ::GetWindowLong(GetSafeHwnd(), GWL_EXSTYLE);
style &= ~WS_EX_CLIENTEDGE;
::SetWindowLong(GetSafeHwnd(), GWL_EXSTYLE, style);
ShowWindow(SW_SHOWMAXIMIZED);
return;
}
if (m_bInsideMDIFrame)
{
CMDIChildWndEx::ActivateFrame(nCmdShow);
return;
}
long style = ::GetWindowLong(GetSafeHwnd(), GWL_STYLE);
style &= ~WS_MINIMIZEBOX & ~WS_MAXIMIZEBOX;
::SetWindowLong(GetSafeHwnd(), GWL_STYLE, style);
style = ::GetWindowLong(GetSafeHwnd(), GWL_EXSTYLE);
style &= ~WS_EX_CLIENTEDGE;
::SetWindowLong(GetSafeHwnd(), GWL_EXSTYLE, style);
SetWindowPos(NULL, 0, 0, 0, 0, SWP_DRAWFRAME | SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOSIZE);
CFrameWnd::ActivateFrame(SW_SHOWNOACTIVATE);
}
BOOL CMyFrame::LoadFrame(UINT nIDResource, DWORD dwDefaultStyle,
CWnd* pParentWnd, CCreateContext* pContext)
{
if (g_globalVariables.GetParentWnd() == NULL)
{
if (m_bInsideMDIFrame)
return CMDIChildWndEx::LoadFrame(nIDResource, dwDefaultStyle, pParentWnd, pContext);
return CFrameWnd::LoadFrame(nIDResource, dwDefaultStyle, pParentWnd, pContext);
}
ASSERT(m_nIDHelp == 0 || m_nIDHelp == nIDResource);
m_bInsideMDIFrame = FALSE;
m_nIDHelp = nIDResource; // ID for help context (+HID_BASE_RESOURCE)
CString strFullString;
if (strFullString.LoadString(nIDResource))
AfxExtractSubString(m_strTitle, strFullString, 0); // first sub-string
VERIFY(AfxDeferRegisterClass(AFX_WNDFRAMEORVIEW_REG));
dwDefaultStyle = WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS;
// attempt to create the window
LPCTSTR lpszClass = GetIconWndClass(dwDefaultStyle, nIDResource);
LPCTSTR lpszTitle = m_strTitle;
if (!CFrameWnd::Create(lpszClass, lpszTitle, dwDefaultStyle, rectDefault, g_globalVariables.GetParentWnd(), 0, 0, pContext))
return FALSE; // will self destruct on failure normally
// save the default menu handle
ASSERT(m_hWnd != NULL);
m_hMenuDefault = ::GetMenu(m_hWnd);
// load accelerator resource
LoadAccelTable(MAKEINTRESOURCE(nIDResource));
if (pContext == NULL) // send initial update
SendMessageToDescendants(WM_INITIALUPDATE, 0, 0, TRUE, TRUE);
return TRUE;
}</pre>
Another difference is if application uses MDI tabs, in my tests everything indicates that CMDIChildWndEx does not work without the ribbon.
Has anyone had the same problem? Please, can anyone help me?
Thank you very much
|
|
|
|
|
I have about 1800 text files in a dir and their number is slowly growing (several files in a day). The size of a file is about 40 kB.
I need to enumerate all the file with the ".states" extension, open the file, check to see if there is a line that starts with a particular sequence of 4 chars and if the line exists, I save the line in a std::vector.
I use the following code, but it takes very long time at the first run (the subsequent runs are very fast):
struct _finddata_t fd; long hFile;
if((hFile=_findfirst("*.states", &fd))== -1L) return; do {
FILE *f= fopen(fd.name, "rS");
while(fgets(buf, sizeof(buf), f)) {
if(0 == _strnicmp(buf, "ABCD", 4)) {
Save buf in a std::vector
break;
}
}
fclose(f);
} while(_findnext(hFile, &fd) == 0);
_findclose(hFile);
Is there any way to speedup the code?
If I merge all the files in a single file, I solve the problem, but I prefer to keep all the original files.
|
|
|
|
|
Are the files that were in that folder on Monday (for example) still there on Tuesday? In other words, are you processing every file in that folder, or just the new ones?
Keep in mind that file I/O is arguably one of the slowest operations on a computer. It can be sped up to a marginal degree, but you are ultimately at the mercy of the disk.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
modified 31-Jan-19 12:11pm.
|
|
|
|
|