473,769 Members | 2,377 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to write code which minimizes page faults?

Hi!

Pre-requisites:
-------------------
1) Consider I'm about to write a quite large program. Say 500 K
lines.
2) Part of this code will consist of 50 structs with, say, no more
than at most 1K bytes of data.
3) These structs are to be used by all of the other 500K lines in
various places.
4) Linux, SUN Solaris

Design decisions:
-------------------
- Add functions to the structs so they handle their own data. Kind of
C++ OOP.
- Just make the structs carry data, and write macros to handle the
data of each struct, and insert those macros in appropriate places
in the 500 K lines of code, wherever they are used.

This question does not deal in what is good programming in terms of
macros or OOP and data encapsulation in C!!!!! So please no remarks
on this unless it makes your answers to the questions below more
clear.

Question:
--------------------
- I'm afraid that adding code/functions to structs results in worse
locality, i.e. this will result in increased paging. Is that so?

- Is inserting code in the 500K lines wherever it's needed, worth
the effort? or am I over exaggerating the risk and consequences of
page faults?

Thanks in advance
/Sune

Nov 15 '05
27 5691

"akarl" <fu********@com hem.se> wrote

Why do you want to use C (a high level assembler) for such a large
program?

C++ is a good language for many complex projects. It doesn't follow that C
is a bad or worse language for such projects.

Nov 15 '05 #11
Default User wrote:
akarl wrote:
Why do you want to use C (a high level assembler) for such a large
program?


Why do you want to make false and ridiculous statements on newsgroups?


No, let me rephrase that:

Why do you want to use a low-level and unsafe programming language
for a project of this size?

It's not a rant, I'm only curious.
August
Nov 15 '05 #12
In article <as************ *******@newsb.t elia.net>,
akarl <fu********@com hem.se> wrote:
let me rephrase that: Why do you want to use a low-level and unsafe programming language
for a project of this size? It's not a rant, I'm only curious.


Would it be better if they were to do the proposed project in LISP ?
APL? perl ?
--
Any sufficiently old bug becomes a feature.
Nov 15 '05 #13
akarl wrote:

Why do you want to use a low-level and unsafe programming language
for a project of this size?
Why would you bother to post to a newsgroup dedicated to a language you
despise.
It's not a rant, I'm only curious.


It's more a troll, I'd say. So,
*plonk*


Brian
Nov 15 '05 #14
Default User wrote:
akarl wrote:
Why do you want to use a low-level and unsafe programming language
for a project of this size?


Why would you bother to post to a newsgroup dedicated to a language you
despise.


I don't. I think C is good for making small, efficient and/or low-level
programs.
It's not a rant, I'm only curious.


It's more a troll, I'd say. So,


The comp.lang.* groups are not only for religious followers of one
language, you know. I would certainly be a troll if I said that C sucks
in every respect, but I haven't.

Since neither you nor Sune seem to be able to answer my question you
probably have no good answer, so I won't be bothering you with it.
August
Nov 15 '05 #15
akarl <fu********@com hem.se> wrote:
Default User wrote:
akarl wrote:
Why do you want to use C (a high level assembler) for such a large
program?
Why do you want to make false and ridiculous statements on newsgroups?


No, let me rephrase that:

Why do you want to use a low-level and unsafe programming language
for a project of this size?


Let me, then, rephrase Brian's reply to fit your rephrased question:

Why do you want to make false and ridiculous statements on newsgroups?
It's not a rant, I'm only curious.


Feh.

Richard
Nov 15 '05 #16
Hi guys!

Thanks for giving me insight on a non-issue it seems. I'm usually a C++
programmer so that's why some of my suggestions went off topic (like
functions in structs).

The reason I need info on C is that I'm rather fed up with OO and think
I can achieve the same abstractions and the necessary level of
encapsulation in C without having to instantiate 25-100 objects in the
traffical path.

I believe C with small intelligent C++ objects is the way to
go...together with exceptions, RAII etc. Nice mix I think...

BRs
/Olle

Nov 15 '05 #17

"akarl" <fu********@com hem.se> wrote in message
news:vP******** ***********@new sb.telia.net...
Default User wrote:
akarl wrote:
Why do you want to use a low-level and unsafe programming language for a
project of this size?

Since neither you nor Sune seem to be able to answer my question you
probably have no good answer, so I won't be bothering you with it.

C is a simple language, so maintenance and configuration is easy. That's
what you probably mean by "low level".
All programming languages are unsafe, in that none can guarantee that the
programmer hasn't made an error. Since C is so simple, mistakes are unlikely
to be due to some quirk of the language.
Nov 15 '05 #18
Malcolm wrote:
"akarl" <fu********@com hem.se> wrote in message
news:vP******** ***********@new sb.telia.net...
Default User wrote:
akarl wrote:

Why do you want to use a low-level and unsafe programming language for a
project of this size?
Since neither you nor Sune seem to be able to answer my question you
probably have no good answer, so I won't be bothering you with it.


C is a simple language, so maintenance and configuration is easy. That's
what you probably mean by "low level".


No, I mean direct memory access, raw pointers etc.
All programming languages are unsafe, in that none can guarantee that the
programmer hasn't made an error.
A safe language is a language where a large class of errors are detected
when they occur and not when data gets corrupted. Such a language
provides e.g. array bounds checking, garbage collection and restricted
pointers.

Since C is so simple, mistakes are unlikely to be due to some quirk of the language.


Lots of laughs. You're being ironic I hope. The quirks of C is part of
it's charm and success. If you want to see a *real* simple (procedural)
language, check out Oberon-2.

August
Nov 15 '05 #19
>> All programming languages are unsafe, in that none can guarantee that the
programmer hasn't made an error.


Unless, of course, it is impossible to make an error. Consider an
assembly language with one-bit opcodes, NOOP and HALT, which can
be arranged in any order. (A HALT opcode is implied if you run
off the end of the program.) Of course, you can't do anything
USEFUL with it, either. All those ugly things that cause errors
like pointers, variables, arithmetic, loops, etc. are prohibited.

Gordon L. Burditt
Nov 15 '05 #20

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2746
by: benben | last post by:
Is there a standard guidline to avoid or minimize page faults when manipulating data collections in C++? ben
1
6557
by: tbatwork828 | last post by:
I've PerfMon-ed our application for several days now and it consistently averages 2000 Page Faults/sec, and accumulates on average about 4 mill page faults during 35 mins. During the same monitoring time of 35 mins, there is never any sustained occurence of hard page faults -as a matter of fact, almost on avg 98+ % of the entire time the app is experiencing soft page faults. The processor rarely ever gets over 70-80% for a sustained...
4
3807
by: tbatwork828 | last post by:
Related to my other post on Graphics.FillRectangle and a lot of page faults caused by this call... We determine that when Control.DoubleBuffer=true to avoid the flicker effect, Graphics.FillRectangle causes a lot of soft page faults - order of 700/sec and more... When Control.DoubleBuffer=false, we have no page faults at all - 0/sec. Has anyone seen this behavior and how did they resolve it...? What are our options...? Does...
0
1042
by: Crirus | last post by:
Hello! I cant understand why my application generate lots of page faults as task manager shows... Something related to MouseMove, I guess...I scroll a large bitmap with MouseMove and seems that if I intensily do htat the page faults increase Any thoughts? -- Ceers,
2
4906
by: Crirus | last post by:
I made a simple test... loaded an image from file and draw it on a form In mouse move, I just refresh the form.... that cause 1 000 000 page faults (as task manager shows) in less than a minute.. what is that? -- Ceers, Crirus ------------------------------ If work were a good thing, the boss would take it all from you
2
4157
by: David Morgan | last post by:
Hi Have 4Gb of RAM and plenty of free disk. Those page faults are for DLLHOST.EXE using ~370Mb RAM. inetinfo.exe has 403,106,036 page faults at the time of writing and is using ~145Mb RAM. Why so many page faults. System uptime ~500 hours. The ASP-based site does interface with a SQL Server instance on a completely
1
3558
by: cablitoEscobar | last post by:
The problem lies in the fact that whenever I call CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0) a page fault occurs. The fact is I have a timer set to take a snap-shot per second and the page faults just go on increasing. It is very well isolated that only when calling the API the page fault occurs.
3
1832
by: scotp | last post by:
Does anyone know what would cause excessive page faults running the js function below? The most common browser used is IE 6. The page has records that include text & checkbox inputs. Each record also has a hidden input named "questions", whose value is an id that is used in the name of inputs to be disabled. The number of page faults increases dramatically as records increase. I know it is the for loop that is taking the extra time,...
4
2169
by: none | last post by:
I have an ASP.NET application, hosted on two web servers. I am looking for advice on what should be an acceptable level of page faults on these production servers. If the acceptable level is zero, then where should I begin reducing page faults in code? What should I look for in code to reduce page faults? Having to reduce page faults is something I have not had been tasked with before, so I am not sure what is acceptable and where to...
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9999
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8876
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7413
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6675
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5310
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.