portability

What is fadvise/madvise equivalent on windows?

别等时光非礼了梦想. 提交于 2019-11-27 06:04:41
问题 On UNIX, I can, for example, tell the OS that the mapping will be needed in the future with posix_fadvise(POSIX_FADV_WILLNEED) . It will then read-ahead the data if it feels so. How to tell the access intend to Windows ? 回答1: Actually, as Anders mostly suggested, there is no such method in the memory management functions available in Windows 7 and earlier . 2 different ways exists to do something similar : Read the data asynchronously with ReadFileEx. The data might then still be in the file

Why does glibc's strlen need to be so complicated to run quickly?

谁都会走 提交于 2019-11-27 04:58:55
问题 I was looking through the strlen code here and I was wondering if the optimizations used in the code are really needed? For example, why wouldn't something like the following work equally good or better? unsigned long strlen(char s[]) { unsigned long i; for (i = 0; s[i] != '\0'; i++) continue; return i; } Isn't simpler code better and/or easier for the compiler to optimize? The code of strlen on the page behind the link looks like this: /* Copyright (C) 1991, 1993, 1997, 2000, 2003 Free

STL containers element destruction order

≡放荡痞女 提交于 2019-11-27 04:47:50
Does ISO C++ standard mandate any sort of destruction order of objects inside STL containers? Are std::list / std::vector / std::map elements destroyed starting from the beginning or the end of the container? Can I rely on std::map storing its elements in std::pair s internally so a key in a pair is destroyed before its value (or vice versa)? Unspecified in the standard. Yes, but this means that the key is destroyed after its associated value. Unspecified Yes, you can depend on std::map storing it's elements in std::pairs, but I don't see anything which specifies the Key portion of a std::pair

How do I detect if I'm running MATLAB or Octave?

感情迁移 提交于 2019-11-27 04:35:06
I need to write code that should run equally well in Octave and on MATLAB. Problem is that it needs to do some GUI stuff, which MATLAB and Octave handle completely differently. Is there a way I can detect if I'm running MATLAB or Octave, in order to call the right function? You could use the following test to differentiate Octave from MATLAB: isOctave = exist('OCTAVE_VERSION', 'builtin') ~= 0; Bernhardt Rogge There is also a hint in the wiki on the official octave.org website. They propose the following: Edit: Not all versions of Matlab support '#' for comments so I changed the example to use

C++ Class wrapper around fundamental types

本秂侑毒 提交于 2019-11-27 04:34:38
问题 Many libraries I have seen/used have typedefs to provide portable, fixed size variables, eg int8, uint8, int16, uint16, etc which will be the correct size regardless of platform (and c++11 does it itself with the header stdint.h) After recently using binary file i/o in a small library I'm writing I can see the benefit of using typedefs in this way to ensure the code is portable. However, if I'm going to the trouble of typing "namespace::uint32" rather than using built in fundamental types, I

How to write portable code in c++?

一个人想着一个人 提交于 2019-11-27 04:13:34
What are the things that I should keep in mind to write portable code? Since I'm a c++ beginner, I want to practice it since beginning. Thanks. learn to use the standard library read books (eg. this one ) when you're experienced, learn to use boost Keep platform-specific code separate from reusable code, preferably in a different file but at least in a different function. If you start having #if WIN32 and #if CYGWIN and #if BSD all over the place you'll have a maintenance nightmare. Then, compile on at least two different platforms early and often. Typical choices are Visual C++ on Windows and

How to make designer generated .Net application settings portable

。_饼干妹妹 提交于 2019-11-27 03:36:00
问题 I've been looking at modifying the source of the Doppler podcast aggregator with the goal of being able to run the program directly from my mp3 player. Doppler stores application settings using a Visual Studio designer generated Settings class, which by default serializes user settings to the user's home directory. I'd like to change this so that all settings would be stored in the same directory as the exe. It seems that this would be possible by creating a custom provider class which

Fixed-width integers in C++

此生再无相见时 提交于 2019-11-27 03:10:18
问题 Occasionally I need to use fixed-width integers for communication with external devices like PLCs. I also use them to define bitmasks and perform bit manipulation of image data. AFAIK the C99 standard defines fixed-width integers like int16_t. However the compiler I use, VC++ 2008 doesn't support C99 and AFAIK Microsoft is not planning to support it. My question is what is the best practice for using fixed-width integers in C++? I know that VC++ defines non-standard fixed-width integers like

Android & iOS: How to develop for both?

可紊 提交于 2019-11-27 03:09:30
问题 I want to develop an application for both android and iOS devices. Is there a way to develop the application once and deploy on both? Or is it a must to develop for each platform separately? 回答1: If you want applications that provide a native experience, then you will have to write separate applications. I think the best place to start is with a really nice web version optimized for mobile browsers. I think the nicest web apps are better than a lot of the native apps, but they aren't

Portability of #warning preprocessor directive

时间秒杀一切 提交于 2019-11-27 02:03:23
I know that the #warning directive is not standard C /C++, but several compilers support it, including gcc/g++. But for those that don't support it, will they silently ignore it or will it result in a compile failure? In other words, can I safely use it in my project without breaking the build for compilers that don't support it? It is likely that if a compiler doesn't support #warning, then it will issue an error. Unlike #pragma, there is no recommendation that the preprocessor ignore directives it doesn't understand. Having said that, I've used compilers on various different (reasonably