Q. I’m in my mid-40s and have always found it easy to get an erection, but lately it seems to take longer to get hard and I tend to go soft quicker than I did in the past. Is this something that’s to be expected at my age? Would Viagra help or should I take some other steps to improve erectile function?

A. The early signs of erectile dysfunction serve as a helpful signal that things will probably get worse unless you take proactive steps to improve your overall health. Eating a healthy diet, such as the so-called Mediterranean diet, can be a good way to start.

Such diets are high in heart-healthy nutrients and fats but lower in refined sugars and grains, as well as the unhealthy fats found in red meats, high-fat dairy foods, lard, and tropical oils, such as coconut and palm oils. If you take action quickly enough, you may be able to regain more normal erectile function without resorting to prescription medications.

Other important lifestyle choices include a regular regimen of physical activity, which can begin slowly with brisk walking and progress to more advanced forms of exercise as you gain strength. If you smoke, stop as soon as you can, and if you don’t smoke, don’t start.

Work with your doctor to manage those underlying ailments such as atherosclerosis and diabetes that can increase the risk of ED. Alcohol is all right in moderation, but drinking in excess can make it difficult or even impossible to get an erection.